未验证 提交 0a28f402 编写于 作者: A AlekseyTs 提交者: GitHub

Fix System.InvalidOperationException in IOperation factory for an Option...

Fix System.InvalidOperationException in IOperation factory for an Option statement inside a method body (#23284)

Fixes #23283.
上级 aeb5360b
......@@ -318,7 +318,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
SyntaxKind.RaiseEventStatement,
SyntaxKind.ExpressionStatement,
SyntaxKind.YieldStatement,
SyntaxKind.PrintStatement
SyntaxKind.PrintStatement,
SyntaxKind.OptionStatement
Return True
Case SyntaxKind.IfStatement,
......
......@@ -872,5 +872,42 @@ End Class
' Verify we return null operation for child nodes of member access expression.
Assert.Null(model.GetOperation(expr.Name))
End Sub
<CompilerTrait(CompilerFeature.IOperation)>
<WorkItem(23283, "https://github.com/dotnet/roslyn/issues/23283")>
<Fact()>
Public Sub TestOptionStatement_01()
Dim source = <![CDATA[
Class Test
Sub Method()
Option Strict On 'BIND:"Option Strict On"
End Sub
End Class
]]>.Value
Dim expectedOperationTree = <![CDATA[
IInvalidOperation (OperationKind.Invalid, Type: null, IsInvalid) (Syntax: 'Option Strict On')
Children(0)
]]>.Value
Dim expectedDiagnostics = <![CDATA[
BC30024: Statement is not valid inside a method.
Option Strict On 'BIND:"Option Strict On"
~~~~~~~~~~~~~~~~
]]>.Value
VerifyOperationTreeAndDiagnosticsForTest(Of StatementSyntax)(source, expectedOperationTree, expectedDiagnostics)
End Sub
<CompilerTrait(CompilerFeature.IOperation)>
<WorkItem(23283, "https://github.com/dotnet/roslyn/issues/23283")>
<Fact()>
Public Sub TestOptionStatement_02()
Dim source = <![CDATA[
Option Strict On 'BIND:"Option Strict On"
]]>.Value
VerifyNoOperationTreeForTest(Of StatementSyntax)(source)
End Sub
End Class
End Namespace
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册