Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A Roslyn bug? On non-shared member, I'm getting error that I'm using '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 default value (value) with error BC30369:

Cannot refer to an instance member of a class from within a shared method or shared member initializer without an explicit instance of the class.

Is this really the right error for this case? The method is not shared.

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

Constant expression is required.

what absolutely makes sense.

like image 736
miroxlav Avatar asked Oct 31 '22 21:10

miroxlav


1 Answers

After additional research I think that there is a problem in order of checks made by compiler.

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

Constant expression is required.

Since nothing except constants can be placed into default value of Optional clause, check for the above BC30059 ("Constant expression is required.") should be obviously made "earlier" than the check for BC30369 (shown in question).

I created bug report at Microsoft Connect.

like image 125
miroxlav Avatar answered Nov 11 '22 06:11

miroxlav