-
Notifications
You must be signed in to change notification settings - Fork 88
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.
It was not originally so flexible, see https://github.com/dotnet/csharplang/blob/8bd52cca31b40d9720a98629aae9a0cd89bb92ec/meetings/2017/LDM-2017-12-04.md. But I'm not sure which version of C# got that change.
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 Roslyn change was dotnet/roslyn#23643. According to dotnet/csharplang#1022, this change is in C# 7.3. So OK for the ECMA C# 7 spec.
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. |
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.
(Like Nigel, I'm basically happy with this, but I agree with the ordering flexibility.)
@@ -3056,6 +3056,7 @@ When the first parameter of a method includes the `this` modifier, that method i | |||
|
|||
- It may only be an input parameter if it has a value type | |||
- It may only be a reference parameter if it has a value type or has a generic type constrained to struct | |||
- It shall not be an output parameter. |
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.
While we're here, is it worth being consistent within this bullet list as to whether we end with a period or not?
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.
Also, basically happy as well.
Note for the February meeting: this PR has not changed (as far as I can see) since November. |
(Closure was accidental.) |
[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: