-
Notifications
You must be signed in to change notification settings - Fork 207
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
Discussion issue for grammar ambiguities with non-nullable types #144
Comments
My understanding is that the code above should be interpreted the same in both situations. It is the parser's responsibility to perform arbitrary lookahead in this situation to determine that the |
With set/map literals, Also, I feared that Maybe we could change the syntax for The cheapest parsing algorithm would always combine The next simpler algorithm would never combine a type with I'm sure there are variants in-between, where the parsing depends on the position in the code (is a type expected here or not, with |
This is a gnarly one. Let's say we take: { a as int ? - 3 : 3 } and default to interpreting it as: { (a as int) ? -3 : 3} If that's not what you want, how do you get the other interpretation where { a as (int?) -3 : 3} That feels a little weird to me because in typical formatting, the The other option is to default the other way. Treat the { (a as int) ? -3 : 3} I think we could probably do this by shuffling around the grammar so that a conditional expression's conditional prohibits a This is a breaking change and, unfortunately, I think a fairly common one. |
Seems to me that asking whether Perhaps we should just disallow |
When would one want |
Assuming I needed to write that, I'd want to write it as |
I suppose so, but it feels weird to prevent a semantically meaningful operator for syntactic reasons. If we add other kinds of type annotations, we'll probably run into this problem again. I can also imagine code that might want to do this. Consider some API that accepts
Good point. :) |
Ok, so for the conditional expression ambiguity, it sounds like we can resolve by first trying to parse as a conditional expression, and so prefer the parse |
That is certainly my understanding of this situation. I'm making parser
mods to that end unless I hear otherwise.
…On Wed, Dec 19, 2018 at 1:55 PM Leaf Petersen ***@***.***> wrote:
Ok, so for the conditional expression ambiguity, it sounds like we can
resolve by first trying to parse as a conditional expression, and so prefer
the parse (a is int) ? -3 : 3 over the parse (a is int?) -3 : 3.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#144 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACwgcHb7Q0HCI_abyVZs04NR-2IKsWXmks5u6ouxgaJpZM4ZXS7C>
.
|
A note on grammar: the grammar for types will only allow a single
So int ? ? x = 3; is a parse error. Also, |
Agreed. That is the case and I've just added parser tests to ensure as much. |
The grammar has now been defined, including the ambiguity introduced by null-aware index operators. |
This issue is to discuss and resolve any parsing ambiguities associated with non-nullable type syntax.
Known potential ambiguities:
a is int ? - 3 : 3;
cc @lrhn @munificent @eernstg @danrubel
The text was updated successfully, but these errors were encountered: