Below test fails as SemanticModel.GetOperation returns Nothing instead of an IFieidlInitializerOperation:
<Fact>
Public Sub SimpleArrayCreation_WithImplicitArrayInitializer_02()
Dim source = <![CDATA[
Class C
Private s1(10) As Integer'BIND:"s1(10)"
End Class
]]>.Value
Dim expectedOperationTree = <![CDATA[
IFieldInitializerOperation (Field: C.s1 As System.Int32()) (OperationKind.FieldInitializer, Type: null) (Syntax: 's1(10)')
IArrayCreationOperation (OperationKind.ArrayCreation, Type: System.Int32(), IsImplicit) (Syntax: 's1(10)')
Dimension Sizes(1):
IBinaryOperation (BinaryOperatorKind.Add, Checked) (OperationKind.BinaryOperator, Type: System.Int32, Constant: 11, IsImplicit) (Syntax: '10')
Left:
ILiteralOperation (OperationKind.Literal, Type: System.Int32, Constant: 10) (Syntax: '10')
Right:
ILiteralOperation (OperationKind.Literal, Type: System.Int32, Constant: 1, IsImplicit) (Syntax: '10')
Initializer:
null
]]>.Value
Dim expectedDiagnostics = String.Empty
VerifyOperationTreeAndDiagnosticsForTest(Of ModifiedIdentifierSyntax)(source, expectedOperationTree, expectedDiagnostics)
End Sub
Related to bug https://github.com/dotnet/roslyn/issues/26780, but this one seems to be an underlying binder issue. Bound tree contains a BoundFieldInitializer node with the ModifiedIdentifierSyntax as its underlying syntax, but GetMemberSemanticModel returns Nothing for this node when invoked from GetOperation invocation on this node.
While fixing this issue, please also add a flow analysis test for this case to verify that field initializer is rewritten into an assignment operation with the field reference as the target.
Below test fails as
SemanticModel.GetOperation
returns Nothing instead of anIFieidlInitializerOperation
:Related to bug https://github.com/dotnet/roslyn/issues/26780, but this one seems to be an underlying binder issue. Bound tree contains a
BoundFieldInitializer
node with theModifiedIdentifierSyntax
as its underlying syntax, but GetMemberSemanticModel returns Nothing for this node when invoked from GetOperation invocation on this node.