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

Syntax: allow empty case without when #6367

Merged

Conversation

straight-shoota
Copy link
Member

Fixes #6318

The following is no longer a syntax error:

case foo # expands to `foo`
end

case foo # expands to `foo; bar`
else
  bar
end

While an empty case doesn't make much sense in regular code, it is useful for automatically generated when branches (for example in a macro) and avoids extra effort to prevent empty case nodes.

This also fixes a parsing error for case without condition (case; when true; end) and adds specs for this.

The following is no longer a syntax error:
```
case foo # expands to `foo`
end

case foo # expands to `foo; bar`
else
  bar
end
```

While an empty case doesn't make much sense in regular code, it is
useful for automatically generated `when` branches (for example in a macro)
and avoids extra effort to prevent empty case nodes.

This also fixes a parsing error for `case` without condition (`case;
when true; end`).
@wooster0
Copy link
Contributor

wooster0 commented Jul 12, 2018

But there are still 2 error messages left that say "expecting when, else or end".
They should be changed to just "expecting end" since empty cases are allowed now.

@straight-shoota
Copy link
Member Author

straight-shoota commented Jul 12, 2018

@rooster After a case (or when) the parser expects either of when, else, end. This is completely fine and the error message was actually incorrect before this commit, because after case it required a when.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow empty case without when
5 participants