-
Notifications
You must be signed in to change notification settings - Fork 86
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
Grammar rule *parameter_modifier* disallows valid V7 constructs #1209
base: draft-v8
Are you sure you want to change the base?
Conversation
Re my second suggestion, I just found the following in §15.6.2.1:
That said, having the new bullet I proposed clarifies it at the parameter end of the call in the case of extension methods, which are not singled out by the above quote. |
@@ -2130,7 +2130,7 @@ default_argument | |||
|
|||
parameter_modifier | |||
: parameter_mode_modifier | |||
| 'this' | |||
| 'this' parameter_mode_modifier? |
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.
The ordering is flexible:
| 'this' parameter_mode_modifier? | |
| 'this' parameter_mode_modifier? | |
| parameter_mode_modifier? 'this' |
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.
My test shows that the order is indeed flexible. Given Nigel's proposal, this
on its own would be ambiguous, but I think ANTLR chooses the lexical-first rule that matches, right, Nigel?
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.
@RexJaeschke – Yes, ANTLR resolves such ambiguity by picking the first alternative. We have noted elsewhere where the grammar relies on this, however in this case as the two alternatives represent exactly the same thing I don’t think a note is necessary.
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.
Requires a change to the grammar, apart from that the changes are good.
In the preexisting text I did notice that a reference parameter can be of a generic type constrained to a struct, an input parameter cannot be, and there appears to be no explanation why. The answer can be found in the Readonly references proposal, should something (normative or informative) be added?
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.
Can we rename parameter_modifier
to parameter_modifiers
? It doesn't feel like this ref
is a single parameter modifier. This is purely a stylistic thing, and I'm happy to be overruled.
I'll vote against on this one – not because I think the current naming in this area is good, it isn’t really, but because making it plural won’t make it any better so stick with the status quo. |
[I stumbled on this today while looking at how to spec the addition of
scoped
to a parameter for a future version.]The relevant grammar for method parameters in §15.6.2.1 is, as follows:
Rule parameter_modifier allows parameter_mode_modifier or
this
, but not both. However, two combinations of these are permitted, as follows:This possibility is supported by the text in §15.6.10 Extension methods, which states:
I propose the following grammar change:
Now this new grammar also allows
this out
, which according to my compiler is not permitted [CS8328], and that suggests we also add to the extension bullet list above, the following constraint: