提交 15133604 编写于 作者: A AlekseyTs

Avoid an InvalidCastException while calculating LocalSyntaxOffset within...

Avoid an InvalidCastException while calculating LocalSyntaxOffset within synthetic lambda. (changeset 1352239)
上级 8fef5b5d
......@@ -238,17 +238,13 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Return False
End Function
Friend Shadows Function GetSyntax() As LambdaExpressionSyntax
Return DirectCast(Me.Syntax, LambdaExpressionSyntax)
End Function
Friend Overrides Function CalculateLocalSyntaxOffset(localPosition As Integer, localTree As SyntaxTree) As Integer
Dim syntax = Me.GetSyntax()
Dim syntax = TryCast(Me.Syntax, LambdaExpressionSyntax)
' Assign -1 offset to all variables that are associated with the header.
' We can't assign >=0 since user-defined variables defined in the first statement of the body have 0
' and user-defined variables need to have a unique syntax offset.
If localPosition = syntax.Begin.SpanStart Then
If syntax Is Nothing OrElse localPosition = syntax.Begin.SpanStart Then
Return -1
End If
......
......@@ -10816,6 +10816,27 @@ End Module
CreateCompilationWithMscorlibAndVBRuntimeAndReferences(compilationDef, additionalRefs:={SystemCoreRef}, options:=TestOptions.ReleaseDll).AssertNoDiagnostics()
End Sub
<Fact, WorkItem(1042011)>
Public Sub LambdaWithClosureInQueryExpressionAndPDB()
Dim compilationDef =
<compilation name="QueryExpressions">
<file name="a.vb">
Imports System.Linq
Module Module1
Sub Main()
Dim x = From y In {1} Select Function() y
End Sub
End Module
</file>
</compilation>
CompileAndVerify(compilationDef, options:=TestOptions.DebugExe)
End Sub
End Class
End Namespace
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册