Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CaseNode#branches #87

Merged
merged 2 commits into from Aug 2, 2020
Merged

Add CaseNode#branches #87

merged 2 commits into from Aug 2, 2020

Conversation

marcandre
Copy link
Contributor

I was surprised that IfNode#branches returns a array with a single item for if foo; else; end. I was expecting [nil, nil], not just [nil].

I mimicked this behavior for CaseNode as it seems natural to have this symmetry, but I wonder which is best. Anyone has an idea? cc/ @fatkodima

@fatkodima
Copy link
Contributor

Symmetry is good, but it seems to me also that it should return [nil, nil] instead of just [nil] for provided example.

@marcandre
Copy link
Contributor Author

marcandre commented Aug 1, 2020

There are different possibilities for IfNode#branches

  1. always return the last else branch, even if it is only implicit:
if foo; end # => [nil, nil]
if foo; elsif bar; end # => [nil, nil, nil]
  1. return the last else branch only if there's an explicit keyword
if foo; end # => [nil]
if foo; else; end # => [nil, nil]
if foo; elsif bar; end # => [nil, nil]
if foo; elsif bar; else; end # => [nil, nil, nil]
  1. return the last else branch only if there keyword and some code in there [current]
if foo; else; end # => [nil]
if foo; else; 42; end # => [nil, s(:int, 42)]
if foo; elsif bar; else; end # => [nil, nil]
if foo; elsif bar; else; 42; end # => [nil, nil, s(:int, 42)]

I like #3 the least.

The same question exist for case and I'd like the answer to be the same... @fatkodima you prefer #2 or #1?

@marcandre marcandre marked this pull request as draft August 1, 2020 22:37
@fatkodima
Copy link
Contributor

No. 2 seems the most logical to me.

@marcandre
Copy link
Contributor Author

Thank you :-)

I made the tweak, and not a single spec fails, in rubocop-ast or rubocop... I put this as "potentially breaking" in the Changelog.

@marcandre marcandre marked this pull request as ready for review August 2, 2020 00:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants