From dd00d4ae623b395b65e050157d234effabcb7350 Mon Sep 17 00:00:00 2001 From: AlekseyTs Date: Mon, 3 Nov 2014 14:34:08 -0800 Subject: [PATCH] VB: Bug fixes for Async methods. ***NO_CI*** (changeset 1365691) --- .../Portable/Compilation/MethodCompiler.vb | 36 +++--- ...ter.AsyncMethodToClassRewriter.Spilling.vb | 2 +- .../Lowering/SyntheticBoundNodeFactory.vb | 5 +- .../Test/Semantic/Semantics/AsyncAwait.vb | 104 ++++++++++++++++++ 4 files changed, 128 insertions(+), 19 deletions(-) diff --git a/Src/Compilers/VisualBasic/Portable/Compilation/MethodCompiler.vb b/Src/Compilers/VisualBasic/Portable/Compilation/MethodCompiler.vb index 76afad7be35..efac7c5193a 100644 --- a/Src/Compilers/VisualBasic/Portable/Compilation/MethodCompiler.vb +++ b/Src/Compilers/VisualBasic/Portable/Compilation/MethodCompiler.vb @@ -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 diff --git a/Src/Compilers/VisualBasic/Portable/Lowering/AsyncRewriter/AsyncRewriter.AsyncMethodToClassRewriter.Spilling.vb b/Src/Compilers/VisualBasic/Portable/Lowering/AsyncRewriter/AsyncRewriter.AsyncMethodToClassRewriter.Spilling.vb index 4c4e800c116..f710dfbb38e 100644 --- a/Src/Compilers/VisualBasic/Portable/Lowering/AsyncRewriter/AsyncRewriter.AsyncMethodToClassRewriter.Spilling.vb +++ b/Src/Compilers/VisualBasic/Portable/Lowering/AsyncRewriter/AsyncRewriter.AsyncMethodToClassRewriter.Spilling.vb @@ -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 diff --git a/Src/Compilers/VisualBasic/Portable/Lowering/SyntheticBoundNodeFactory.vb b/Src/Compilers/VisualBasic/Portable/Lowering/SyntheticBoundNodeFactory.vb index dbc9fc35151..254ddea55ba 100644 --- a/Src/Compilers/VisualBasic/Portable/Lowering/SyntheticBoundNodeFactory.vb +++ b/Src/Compilers/VisualBasic/Portable/Lowering/SyntheticBoundNodeFactory.vb @@ -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 diff --git a/Src/Compilers/VisualBasic/Test/Semantic/Semantics/AsyncAwait.vb b/Src/Compilers/VisualBasic/Test/Semantic/Semantics/AsyncAwait.vb index 84d7d46a7a0..f9f55cf22ae 100644 --- a/Src/Compilers/VisualBasic/Test/Semantic/Semantics/AsyncAwait.vb +++ b/Src/Compilers/VisualBasic/Test/Semantic/Semantics/AsyncAwait.vb @@ -5479,5 +5479,109 @@ End Class CompileAndVerify(compilation, expectedOutput:="") End Sub + + + Public Sub Bug1066694() + Dim source = + + + + + + + Dim compilation = CreateCompilationWithReferences(source, {MscorlibRef_v4_0_30316_17626, MsvbRef_v4_0_30319_17929}, TestOptions.ReleaseExe) + + CompileAndVerify(compilation, expectedOutput:= + ) + End Sub + + + Public Sub Bug1068084() + Dim source = + + + + + + + Dim compilation = CreateCompilationWithReferences(source, {MscorlibRef_v4_0_30316_17626}, TestOptions.ReleaseDll) + + AssertTheseEmitDiagnostics(compilation, + +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() + ~~~~~~~~~~~~~~ +) + End Sub + End Class End Namespace -- GitLab