Roslyn error? Regarding the non-shared user, I get the error that I am using the 'shared member initializer'

Have the following trivial code:

Class A Private value As Integer = 1 Sub Action(Optional param1 As Integer = value) End Sub End Class 

Visual Studio complains about the default value with error BC30369 :

It is not possible to refer to a member of a class instance from a common method or the initiator of a shared member without an explicit class instance.

Is this the correct mistake for this case? This method is not used.

In Visual Studio 2012 or 2013, the error in the same case

Constant expression required.

which absolutely makes sense.

+5
source share
1 answer

After further research, I think there is a problem in the order of checks performed by the compiler.

If I change the code by making value member Shared , I get the correct result: Error BC30059

Constant expression required.

Since nothing but constants can be placed in the default value Optional , check above BC30059 (constant expression is mandatory.) Should be explicitly done "earlier" than checking for BC30369 (shown in the question).

I created in Microsoft Connect .

+2
source

All Articles