提交 dd00d4ae 编写于 作者: A AlekseyTs

VB: Bug fixes for Async methods.

***NO_CI***
 (changeset 1365691)
上级 a3d4ddba
......@@ -857,27 +857,29 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
End If
For Each methodWithBody In compilationState.SynthesizedMethods
Dim method = methodWithBody.Method
Dim diagnosticsThisMethod As DiagnosticBag = DiagnosticBag.GetInstance()
If Not methodWithBody.Body.HasErrors Then
Dim method = methodWithBody.Method
Dim diagnosticsThisMethod As DiagnosticBag = DiagnosticBag.GetInstance()
Dim emittedBody = GenerateMethodBody(_moduleBeingBuiltOpt,
method,
methodWithBody.Body,
stateMachineTypeOpt:=Nothing,
variableSlotAllocatorOpt:=Nothing,
debugDocumentProvider:=_debugDocumentProvider,
diagnostics:=diagnosticsThisMethod,
namespaceScopes:=GetNamespaceScopes(methodWithBody.Method))
Dim emittedBody = GenerateMethodBody(_moduleBeingBuiltOpt,
method,
methodWithBody.Body,
stateMachineTypeOpt:=Nothing,
variableSlotAllocatorOpt:=Nothing,
debugDocumentProvider:=_debugDocumentProvider,
diagnostics:=diagnosticsThisMethod,
namespaceScopes:=GetNamespaceScopes(methodWithBody.Method))
_diagnostics.AddRange(diagnosticsThisMethod)
diagnosticsThisMethod.Free()
_diagnostics.AddRange(diagnosticsThisMethod)
diagnosticsThisMethod.Free()
' error while generating IL
If emittedBody Is Nothing Then
Exit For
End If
' error while generating IL
If emittedBody Is Nothing Then
Exit For
_moduleBeingBuiltOpt.SetMethodBody(method, emittedBody)
End If
_moduleBeingBuiltOpt.SetMethodBody(method, emittedBody)
Next
End Sub
......
......@@ -233,7 +233,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
End Function
Private Function SpillValue(expr As BoundExpression, isReceiver As Boolean, <[In], Out> ByRef builder As SpillBuilder) As BoundExpression
If Unspillable(expr) OrElse expr.Kind = BoundKind.FieldAccess AndAlso Unspillable(DirectCast(expr, BoundFieldAccess).ReceiverOpt) Then
If Unspillable(expr) Then
Return expr
ElseIf isReceiver OrElse expr.IsLValue Then
......
......@@ -978,7 +978,10 @@ nextm:
End Function
Public Function [Catch](local As LocalSymbol, block As BoundBlock) As BoundCatchBlock
Return New BoundCatchBlock(Syntax, local, Me.Local(local, False), Nothing, Nothing, block)
Dim m1 = WellKnownMember(Of MethodSymbol)(Microsoft.CodeAnalysis.WellKnownMember.Microsoft_VisualBasic_CompilerServices_ProjectData__SetProjectError)
Dim m2 = WellKnownMember(Of MethodSymbol)(Microsoft.CodeAnalysis.WellKnownMember.Microsoft_VisualBasic_CompilerServices_ProjectData__ClearProjectError)
Return New BoundCatchBlock(Syntax, local, Me.Local(local, False), Nothing, Nothing, block,
hasErrors:=m1 Is Nothing OrElse m2 Is Nothing)
End Function
Public Function SequencePoint(syntax As VisualBasicSyntaxNode, statement As BoundStatement) As BoundStatement
......
......@@ -5479,5 +5479,109 @@ End Class
CompileAndVerify(compilation, expectedOutput:="")
End Sub
<Fact(), WorkItem(1066694, "DevDiv")>
Public Sub Bug1066694()
Dim source =
<compilation>
<file name="a.vb">
<![CDATA[
Imports System
Imports System.Threading.Tasks
Module Module1
Sub Main()
System.Console.WriteLine("Non-Async")
System.Console.WriteLine()
TestLocal()
System.Console.WriteLine()
System.Console.WriteLine("Async")
System.Console.WriteLine()
Task.WaitAll(TestLocalAsync())
End Sub
Sub TestLocal()
Dim l = New TestClass("Unchanged")
l.M1(l, Mutate(l))
System.Console.WriteLine(l.State)
End Sub
Async Function DummyAsync(x As Object) As Task(Of Object)
Return x
End Function
Async Function TestLocalAsync() As Task
Dim l = New TestClass("Unchanged")
l.M1(l, Await DummyAsync(Mutate(l)))
System.Console.WriteLine(l.State)
End Function
Function Mutate(ByRef x As TestClass) As Object
x = New TestClass("Changed")
Return x
End Function
End Module
Class TestClass
Private ReadOnly fld1 As String
Sub New(val As String)
fld1 = val
End Sub
Function State() As String
Return fld1
End Function
Sub M1(arg1 As TestClass, arg2 As Object)
System.Console.WriteLine(Me.State)
System.Console.WriteLine(arg1.State)
End Sub
End Class
]]>
</file>
</compilation>
Dim compilation = CreateCompilationWithReferences(source, {MscorlibRef_v4_0_30316_17626, MsvbRef_v4_0_30319_17929}, TestOptions.ReleaseExe)
CompileAndVerify(compilation, expectedOutput:=
<![CDATA[
Non-Async
Unchanged
Unchanged
Changed
Async
Unchanged
Unchanged
Changed
]]>)
End Sub
<Fact(), WorkItem(1068084, "DevDiv")>
Public Sub Bug1068084()
Dim source =
<compilation>
<file name="a.vb">
<![CDATA[
Imports System.Threading.Tasks
Class Test
Async Sub F()
Await Task.Delay(0)
End Sub
End Class
]]>
</file>
</compilation>
Dim compilation = CreateCompilationWithReferences(source, {MscorlibRef_v4_0_30316_17626}, TestOptions.ReleaseDll)
AssertTheseEmitDiagnostics(compilation,
<expected>
BC35000: Requested operation is not available because the runtime library function 'Microsoft.VisualBasic.CompilerServices.ProjectData.ClearProjectError' is not defined.
Async Sub F()
~~~~~~~~~~~~~~
BC35000: Requested operation is not available because the runtime library function 'Microsoft.VisualBasic.CompilerServices.ProjectData.SetProjectError' is not defined.
Async Sub F()
~~~~~~~~~~~~~~
</expected>)
End Sub
End Class
End Namespace
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册