Skip to content

Grammar rule *parameter_modifier* disallows valid V7 constructs #1209

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

Open
wants to merge 1 commit into
base: draft-v8
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion standard/classes.md
Original file line number Diff line number Diff line change
Expand Up @@ -2130,7 +2130,7 @@ default_argument

parameter_modifier
: parameter_mode_modifier
| 'this'
| 'this' parameter_mode_modifier?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ordering is flexible:

Suggested change
| 'this' parameter_mode_modifier?
| 'this' parameter_mode_modifier?
| parameter_mode_modifier? 'this'

Copy link
Contributor Author

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?

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

;

parameter_mode_modifier
Expand Down Expand Up @@ -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.
Copy link
Contributor

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?

- It shall not be a pointer type.

> *Example*: The following is an example of a static class that declares two extension methods:
Expand Down
Loading