-
Notifications
You must be signed in to change notification settings - Fork 208
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
Is the list of disambiguating tokens in the constructor tearoffs spec too long? #1806
Comments
Thinking about it a bit more, I don't think this is exactly correct. The disambiguation only occurs if the parser has found a bool isGreaterThanZero = x > +0; Even if there were a matching f(x < 0, y > +0); The only time you would need extra parentheses would be in code like this: f(x < y, z > +0); Personally I think that sort of thing is a rare enough corner case that it's not a problem to disambiguate in favor of type arguments. |
Based on an internal email discussion I believe we're currently leaning toward paring the list down to:
The names "continuation tokens" and "stop tokens" reflect the reason why we're proposing to choose these tokens:
Per the email discussion, we're proposing to not accept any other tokens than these after a type arguement selector. Which means that if someone wants to do something weird like |
Given that we've arrived at an answer that we are happy about and this issue is a 'question', I'll close this issue. |
@stereotype441, is there an issue for the implementation? If not, maybe it isn't necessary? |
There's no issue that I'm aware of. The full implementation is in https://dart-review.googlesource.com/c/sdk/+/210941, which I hope to land today. If I can't land it today I'll create an implementation issue. |
…iguities. When the parser encounters a `<` after an expression, it must choose whether to interpret it as a relational operator or a <typeArguments> selector. The disambiguation rule is: if the `<` and the tokens following it *can* be parsed as <typeArguments>, and the token that follows is a member of a privileged set of tokens, then it is treated as a <typeArguments> selector; otherwise it is treated as a relational operator. This change reduces the privileged set of tokens to the following: - the "continuation tokens" `(`, `.`, `==`, and `!=` - the "stop tokens" `)`, `]`, `}`, `;`, `:`, and `,` The names "continuation tokens" and "stop tokens" reflect the rationale for choosing these tokens: - Continuation tokens are tokens that we can reasonably imagine a programmer wanting to place after a type argument selector to *continue* the expression. For example, `if (List<int> == T) ...` is allowed. - Stop tokens are tokens that can't possibly follow a `>` that is a relational operator, because they *stop* the expression that's in progress. For example, `var x = List<int>;` is allowed. If a user wants to follow a <typeArguments> selector with a token other than the ones above, they'll have to parenthesize the expression. So for example, if they want to do `List<int> + 1` (which could be meaningful if an extension method defined `operator +` for the type `Type`), they will have to use parentheses, and instead write `(List<int>) + 1`. Bug: dart-lang/language#1806 Change-Id: I2816cdac24e55eac3cb3e9920e276404c1228d46 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/210941 Commit-Queue: Paul Berry <paulberry@google.com> Reviewed-by: Lasse R.H. Nielsen <lrn@google.com> Reviewed-by: Konstantin Shcheglov <scheglov@google.com> Reviewed-by: Johnni Winther <johnniwinther@google.com>
Thanks! |
@eernstg raised a question in #1805, regarding the list of look-ahead tokens which force the prior tokens to be type arguments:
For reference, the list is currently:
And #1805 proposes to add
is
andas
.The text was updated successfully, but these errors were encountered: