-
Notifications
You must be signed in to change notification settings - Fork 5
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
Translate conditionals in in
statements
#301
Conversation
parser/prism/Translator.cc
Outdated
if (prismStatements->body.size != 1) { | ||
unreachable("In pattern-matching's `in` clause, a guard must have a single statement."); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (prismStatements->body.size != 1) { | |
unreachable("In pattern-matching's `in` clause, a guard must have a single statement."); | |
} | |
ENFORCE(prismStatements->body.size == 1, | |
"In pattern-matching's `in` clause, a guard must have a single statement."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Enforcing this is good for now, but we'll eventually want to tolerate this error and report it as a syntax error.
This is the current Sorbet's parser behaviour:
case quux
# ^^^^ error: unexpected token "case"
in x if 1, 2
end
Interestingly, the , 2
makes the case
invalid, not the in
or if
. Removing that makes it parse correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in x if 1, 2
in this case doesn't enter this check though because the conditional still only has one statement (x
)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure it's not the 1, 2
? Maybe I'm misunderstanding.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
72f946e
to
2463053
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for rebasing on my big changes!
Can you please open an issue for use to follow up and diagnose this correctly?
case quux
# ^^^^ error: unexpected token "case"
in x if 1, 2
end
parser/prism/Translator.cc
Outdated
if (prismStatements->body.size != 1) { | ||
unreachable("In pattern-matching's `in` clause, a guard must have a single statement."); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure it's not the 1, 2
? Maybe I'm misunderstanding.
Added the issue here: #303 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forgot to approve, myb
Motivation
Closes #204
When investigating #204 I found that Parser's
IfGuard
andUnlessGuard
are associated with these comments:And I found that they're not handled by the current pattern translation yet. For example:
So this PR adds support for those cases.
Test plan
See included automated tests.