You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In C# 7, §13.6.4 (Local function declarations) disallows access to this in a local function when the type of this is a struct type. That rule was added to fix #926. It should be verified whether the rule interacts with the Color Color scenario in §12.8.7.2 (Identical simple names and type names).
When the type of this is a struct type, it is a compile-time error for the body of a local function to access this. This is true whether the access is explicit (as in this.x) or implicit (as in x where x is an instance member of the struct). This rule only prohibits such access and does not affect whether member lookup results in a member of the struct.
Example
The following should be allowed, even though the name lookup of Color in Color.Black finds the instance field Color Color and that might be understood as a disallowed access to an instance field of this.
In a member access of the form E.I, if E is a single identifier, and if the meaning of E as a simple_name (§12.8.4) is a constant, field, property, local variable, or parameter with the same type as the meaning of E as a type_name (§7.8.1), then both possible meanings of E are permitted.
The example translates directly to the struct case - Color.Black is fine; Color.Complement() is prohibited.
Closing as not needing any other work - but please shout if you think I've missed something.
Describe the bug
In C# 7, §13.6.4 (Local function declarations) disallows access to
this
in a local function when the type ofthis
is a struct type. That rule was added to fix #926. It should be verified whether the rule interacts with theColor Color
scenario in §12.8.7.2 (Identical simple names and type names).Example
The following should be allowed, even though the name lookup of
Color
inColor.Black
finds the instance fieldColor Color
and that might be understood as a disallowed access to an instance field ofthis
.Expected behavior
Not sure if anything needs to be changed. Perhaps the wording already allows the above.
Additional context
Inspired by #832 and #931 but does not involve
nameof
.The text was updated successfully, but these errors were encountered: