Skip to content

Commit

Permalink
Use proper type for BoundAwaitOperator in VB statement
Browse files Browse the repository at this point in the history
  • Loading branch information
jcouv committed Apr 15, 2023
1 parent 0368609 commit 2221e47
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -510,5 +510,35 @@ static async Task M(bool b, int i)
";
VerifyFlowGraphAndDiagnosticsForTest<BlockSyntax>(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()
{
/*<bind>*/await M2()/*</bind>*/;
}
static Task<string> M2() => throw null;
}
";
string expectedOperationTree = @"
IAwaitOperation (OperationKind.Await, Type: System.String) (Syntax: 'await M2()')
Expression:
IInvocationOperation (System.Threading.Tasks.Task<System.String> C.M2()) (OperationKind.Invocation, Type: System.Threading.Tasks.Task<System.String>) (Syntax: 'M2()')
Instance Receiver:
null
Arguments(0)
";
var expectedDiagnostics = DiagnosticDescription.None;

VerifyOperationTreeAndDiagnosticsForTest<AwaitExpressionSyntax>(source, expectedOperationTree, expectedDiagnostics);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ Class C
End Class]]>.Value

Dim expectedOperationTree = <![CDATA[
IAwaitOperation (OperationKind.Await, Type: System.Void, IsInvalid) (Syntax: 'Await UndefinedTask')
Expression:
IAwaitOperation (OperationKind.Await, Type: ?, IsInvalid) (Syntax: 'Await UndefinedTask')
Expression:
IInvalidOperation (OperationKind.Invalid, Type: ?, IsInvalid) (Syntax: 'UndefinedTask')
Children(0)
]]>.Value
Expand Down Expand Up @@ -134,8 +134,8 @@ Class C
End Class]]>.Value

Dim expectedOperationTree = <![CDATA[
IAwaitOperation (OperationKind.Await, Type: System.Void, IsInvalid) (Syntax: 'Await i')
Expression:
IAwaitOperation (OperationKind.Await, Type: ?, IsInvalid) (Syntax: 'Await i')
Expression:
IParameterReferenceOperation: i (OperationKind.ParameterReference, Type: System.Int32, IsInvalid) (Syntax: 'i')
]]>.Value

Expand All @@ -162,8 +162,8 @@ Class C
End Class]]>.Value

Dim expectedOperationTree = <![CDATA[
IAwaitOperation (OperationKind.Await, Type: System.Void, IsInvalid) (Syntax: 'Await')
Expression:
IAwaitOperation (OperationKind.Await, Type: ?, IsInvalid) (Syntax: 'Await')
Expression:
IInvalidOperation (OperationKind.Invalid, Type: null, IsInvalid) (Syntax: '')
Children(0)
]]>.Value
Expand Down Expand Up @@ -211,5 +211,37 @@ BC30800: Method arguments must be enclosed in parentheses.

VerifyOperationTreeAndDiagnosticsForTest(Of ExpressionStatementSyntax)(source, expectedOperationTree, expectedDiagnostics, useLatestFramework:=True)
End Sub

<CompilerTrait(CompilerFeature.IOperation)>
<Fact, WorkItem("https://github.com/dotnet/roslyn/issues/67616")>
Public Sub TestAwaitExpression_InStatement()
Dim source = <![CDATA[
Imports System.Threading.Tasks

Public Module Program
Public Async Function M() As Task(Of Integer)
Await M2()'BIND:"Await M2()"
Return 0
End Function

Public Function M2() As Task(Of String)
Throw New System.Exception()
End Function
End Module
]]>.Value

Dim expectedOperationTree = <![CDATA[
IAwaitOperation (OperationKind.Await, Type: System.String) (Syntax: 'Await M2()')
Expression:
IInvocationOperation (Function Program.M2() As System.Threading.Tasks.Task(Of System.String)) (OperationKind.Invocation, Type: System.Threading.Tasks.Task(Of System.String)) (Syntax: 'M2()')
Instance Receiver:
null
Arguments(0)
]]>.Value

Dim expectedDiagnostics = String.Empty

VerifyOperationTreeAndDiagnosticsForTest(Of AwaitExpressionSyntax)(source, expectedOperationTree, expectedDiagnostics, useLatestFramework:=True)
End Sub
End Class
End Namespace

0 comments on commit 2221e47

Please sign in to comment.