提交 93819e3d 编写于 作者: T Tomáš Matoušek 提交者: Jinu

VB EE: Properly handle syntax errors in synthesized assignments (#22647)

* VB EE: Properly handle syntax errors in synthesized assignments

* Fix test
上级 72bff3e5
......@@ -173,7 +173,10 @@ private static ImmutableArray<Alias> GetAliases(DkmClrRuntimeInstance runtimeIns
},
out error);
Debug.Assert((r.ResultProperties.Flags & DkmClrCompilationResultFlags.PotentialSideEffect) == DkmClrCompilationResultFlags.PotentialSideEffect);
Debug.Assert(
r.CompileResult == null && r.ResultProperties.Flags == default ||
(r.ResultProperties.Flags & DkmClrCompilationResultFlags.PotentialSideEffect) == DkmClrCompilationResultFlags.PotentialSideEffect);
result = r.CompileResult.ToQueryResult(this.CompilerId, r.ResultProperties, runtimeInstance);
}
catch (Exception e) when (ExpressionEvaluatorFatalError.CrashIfFailFastEnabled(e))
......
......@@ -38,6 +38,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.ExpressionEvaluator
Dim syntaxTree = expression.CreateSyntaxTree()
diagnostics.AddRange(syntaxTree.GetDiagnostics())
If diagnostics.HasAnyErrors Then
Return Nothing
End If
' Any Diagnostic spans produced in binding will be offset by the length of the "target" expression text.
' If we want to support live squiggles in debugger windows, SemanticModel, etc, we'll want to address this.
Dim targetSyntax = SyntaxHelpers.ParseDebuggerExpressionInternal(SourceText.From(target), consumeFullText:=True)
......
......@@ -471,6 +471,27 @@ End Class
End If
End Sub
<Fact, WorkItem(18531, "https://github.com/dotnet/roslyn/issues/18531")>
Public Sub SyntaxErrors()
Const source = "
Class C
Shared Function F(x As String) As Object
Return x
End Function
End Class
"
Dim comp = CreateCompilationWithMscorlib({source}, options:=TestOptions.DebugDll)
WithRuntimeInstance(comp,
Sub(runtime)
Dim context = CreateMethodContext(runtime, methodName:="C.F")
Dim errorMessage As String = Nothing
Dim result = context.CompileAssignment("x", "", errorMessage, formatter:=DebuggerDiagnosticFormatter.Instance)
Assert.Null(result)
Assert.Equal("error BC30201: Expression expected.", errorMessage)
End Sub)
End Sub
''' <summary>
''' Locals in the generated method should account for temporary slots
''' in the original method. Also, some temporaries may not be included
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册