diff --git a/src/Compilers/CSharp/Test/IOperation/IOperation/IOperationTests_IAwaitExpression.cs b/src/Compilers/CSharp/Test/IOperation/IOperation/IOperationTests_IAwaitExpression.cs index 1a727046665cc..ab42b9a5bf259 100644 --- a/src/Compilers/CSharp/Test/IOperation/IOperation/IOperationTests_IAwaitExpression.cs +++ b/src/Compilers/CSharp/Test/IOperation/IOperation/IOperationTests_IAwaitExpression.cs @@ -510,5 +510,35 @@ static async Task M(bool b, int i) "; VerifyFlowGraphAndDiagnosticsForTest(source, expectedFlowGraph, expectedDiagnostics); } + + [CompilerTrait(CompilerFeature.IOperation)] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/67616")] + public void TestAwaitExpression_InStatement() + { + string source = @" +using System.Threading.Tasks; + +class C +{ + static async Task M() + { + /**/await M2()/**/; + } + + static Task M2() => throw null; +} +"; + string expectedOperationTree = @" +IAwaitOperation (OperationKind.Await, Type: System.String) (Syntax: 'await M2()') + Expression: + IInvocationOperation (System.Threading.Tasks.Task C.M2()) (OperationKind.Invocation, Type: System.Threading.Tasks.Task) (Syntax: 'M2()') + Instance Receiver: + null + Arguments(0) +"; + var expectedDiagnostics = DiagnosticDescription.None; + + VerifyOperationTreeAndDiagnosticsForTest(source, expectedOperationTree, expectedDiagnostics); + } } } diff --git a/src/Compilers/VisualBasic/Portable/Binding/Binder_Expressions.vb b/src/Compilers/VisualBasic/Portable/Binding/Binder_Expressions.vb index adf299521735f..8c734a0c1c4b1 100644 --- a/src/Compilers/VisualBasic/Portable/Binding/Binder_Expressions.vb +++ b/src/Compilers/VisualBasic/Portable/Binding/Binder_Expressions.vb @@ -4892,14 +4892,6 @@ lElseClause: getResult = BadExpression(node, ErrorTypeSymbol.UnknownResultType).MakeCompilerGenerated() End If - Dim resultType As TypeSymbol - - If bindAsStatement Then - resultType = GetSpecialType(SpecialType.System_Void, node, diagnostics) - Else - resultType = getResult.Type - End If - If Not hasErrors Then diagnostics.AddRange(allIgnoreDiagnostics) End If @@ -4909,7 +4901,7 @@ lElseClause: Return New BoundAwaitOperator(node, operand, awaitableInstancePlaceholder, getAwaiter, awaiterInstancePlaceholder, isCompleted, getResult, - resultType, hasErrors) + type:=getResult.Type, hasErrors) End Function Private Shared Function DiagnosticBagHasErrorsOtherThanObsoleteOnes(bag As DiagnosticBag) As Boolean diff --git a/src/Compilers/VisualBasic/Portable/BoundTree/BoundAwaitOperator.vb b/src/Compilers/VisualBasic/Portable/BoundTree/BoundAwaitOperator.vb index 98630db3ca47b..97a61ebf5c827 100644 --- a/src/Compilers/VisualBasic/Portable/BoundTree/BoundAwaitOperator.vb +++ b/src/Compilers/VisualBasic/Portable/BoundTree/BoundAwaitOperator.vb @@ -2,17 +2,13 @@ ' The .NET Foundation licenses this file to you under the MIT license. ' See the LICENSE file in the project root for more information. -Imports Microsoft.CodeAnalysis.Text -Imports Microsoft.CodeAnalysis.VisualBasic.Symbols -Imports Microsoft.CodeAnalysis.VisualBasic.Syntax - Namespace Microsoft.CodeAnalysis.VisualBasic Partial Friend Class BoundAwaitOperator #If DEBUG Then Private Sub Validate() - Debug.Assert(Type.Equals(GetResult.Type) OrElse Type.SpecialType = SpecialType.System_Void) + Debug.Assert(Type.Equals(GetResult.Type)) End Sub #End If diff --git a/src/Compilers/VisualBasic/Portable/Lowering/AsyncRewriter/AsyncRewriter.AsyncMethodToClassRewriter.Await.vb b/src/Compilers/VisualBasic/Portable/Lowering/AsyncRewriter/AsyncRewriter.AsyncMethodToClassRewriter.Await.vb index 4589bb498960e..d8267f8383cf9 100644 --- a/src/Compilers/VisualBasic/Portable/Lowering/AsyncRewriter/AsyncRewriter.AsyncMethodToClassRewriter.Await.vb +++ b/src/Compilers/VisualBasic/Portable/Lowering/AsyncRewriter/AsyncRewriter.AsyncMethodToClassRewriter.Await.vb @@ -2,16 +2,10 @@ ' The .NET Foundation licenses this file to you under the MIT license. ' See the LICENSE file in the project root for more information. -Imports System.Collections.Generic Imports System.Collections.Immutable -Imports System.Threading -Imports Microsoft.Cci Imports Microsoft.CodeAnalysis -Imports Microsoft.CodeAnalysis.Collections Imports Microsoft.CodeAnalysis.PooledObjects -Imports Microsoft.CodeAnalysis.Text Imports Microsoft.CodeAnalysis.VisualBasic.Symbols -Imports Microsoft.CodeAnalysis.VisualBasic.Syntax Namespace Microsoft.CodeAnalysis.VisualBasic @@ -99,7 +93,6 @@ Namespace Microsoft.CodeAnalysis.VisualBasic Me.F.AssignmentExpression(Me.F.Local(resultTemp, True), rewrittenGetResult), clearAwaiterTemp, Me.F.Local(resultTemp, False)) - Else ' STMT: $awaiterTemp.GetResult() ' STMT: $awaiterTemp = Nothing diff --git a/src/Compilers/VisualBasic/Test/IOperation/IOperation/IOperationTests_IAwaitExpression.vb b/src/Compilers/VisualBasic/Test/IOperation/IOperation/IOperationTests_IAwaitExpression.vb index f31df66a0aa53..38e651b36265b 100644 --- a/src/Compilers/VisualBasic/Test/IOperation/IOperation/IOperationTests_IAwaitExpression.vb +++ b/src/Compilers/VisualBasic/Test/IOperation/IOperation/IOperationTests_IAwaitExpression.vb @@ -105,8 +105,8 @@ Class C End Class]]>.Value Dim expectedOperationTree = .Value @@ -134,8 +134,8 @@ Class C End Class]]>.Value Dim expectedOperationTree = .Value @@ -162,8 +162,8 @@ Class C End Class]]>.Value Dim expectedOperationTree = .Value @@ -211,5 +211,37 @@ BC30800: Method arguments must be enclosed in parentheses. VerifyOperationTreeAndDiagnosticsForTest(Of ExpressionStatementSyntax)(source, expectedOperationTree, expectedDiagnostics, useLatestFramework:=True) End Sub + + + + Public Sub TestAwaitExpression_InStatement() + Dim source = .Value + + Dim expectedOperationTree = .Value + + Dim expectedDiagnostics = String.Empty + + VerifyOperationTreeAndDiagnosticsForTest(Of AwaitExpressionSyntax)(source, expectedOperationTree, expectedDiagnostics, useLatestFramework:=True) + End Sub End Class End Namespace