-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Description
As reported by @PaulHazelton in dotnet/vscode-csharp#4763
The following code produces the CS0236 error incorrectly:
#nullable enable
namespace MyNamespace
{
public enum MyEnum
{
VALUE1,
VALUE2
}
public class MyClass
{
public MyEnum? MyEnum { get; set; } = MyEnum.VALUE1; // <-- this line produces CS0236
// If the question mark is omitted, there is no error reported.
}
}
Without the question mark, the compiler correctly knows that MyEnum at (Ln 12, Col 46) is referring to the enum type, not the property. However, with the question mark the error is reported, the compiler seems to think that (Ln 12, Col 47) refers to the property MyEnum instead of the type.
I'm not sure if this issue is caused by the omnisharp-vscode extension, or by a compiler (and I'm not sure what compiler I'm using).
Note that this error is entirely avoidable by having the property name differ from the type name, however this is recommended by Microsoft
CONSIDER giving a property the same name as its type.
For example, the following property correctly gets and sets an enum value named Color, so the property is named Color: