-
Notifications
You must be signed in to change notification settings - Fork 93
Open
Labels
type: bugThe Standard does not describe the language as intended or implementedThe Standard does not describe the language as intended or implemented
Milestone
Description
C# 7 draft §13.6.2 (Local variable declarations) says this about "implicitly typed local variable declaration":
The initializer expression cannot refer to the declared variable itself
As specified and implemented, this disallows also var x = nameof(x);
even though the type of the expression would be unambiguous in this case. That was discussed in dotnet/roslyn#766 and C# Design Meeting Notes for Mar 4, 2015.
However, the wording "refer to the declared variable" seems a bit ambiguous in the "Color Color" case (C# 7 §12.8.7.2, Identical simple names and type names).
In the following example, does nameof(Color.Beige)
refer to the variable, the type, or both?
class C {
void M() {
var Color = nameof(Color.Beige) == "nope" ? (Color)1 : (Color)2;
}
enum Color {
Beige,
Mauve,
Fuchsia,
}
}
(Continued from #831 (comment))
Metadata
Metadata
Assignees
Labels
type: bugThe Standard does not describe the language as intended or implementedThe Standard does not describe the language as intended or implemented