Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use non-void type for BoundAwaitOperator in VB statement #67822

Merged
merged 6 commits into from
Apr 25, 2023

Conversation

jcouv
Copy link
Member

@jcouv jcouv commented Apr 14, 2023

Fixes #67616

I looked for places that use BoundAwaitOperator.Type. The main place that is affected is in AsyncRewriter.AsyncMethodToClassRewriter.Await.vb and it is still correct and covered (Task and Task<T> involve awaiters with GetResult() methods that return void and T respectively).

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Apr 14, 2023
@jcouv jcouv self-assigned this Apr 14, 2023
@jcouv jcouv removed the untriaged Issues and PRs which have not yet been triaged by a lead label Apr 14, 2023
@jcouv jcouv added this to the 17.7 milestone Apr 14, 2023
@jcouv jcouv marked this pull request as ready for review April 15, 2023 08:00
@jcouv jcouv requested a review from a team as a code owner April 15, 2023 08:00
@jcouv
Copy link
Member Author

jcouv commented Apr 17, 2023

@dotnet/roslyn-compiler for review. Thanks

@AlekseyTs
Copy link
Contributor

AlekseyTs commented Apr 20, 2023

Use proper type

Consider to be more specific, "proper" doesn't provide enough clarity, in my opinion.


In reply to: 1516336775

@@ -4909,7 +4901,7 @@ lElseClause:
Return New BoundAwaitOperator(node, operand,
awaitableInstancePlaceholder, getAwaiter,
awaiterInstancePlaceholder, isCompleted, getResult,
resultType, hasErrors)
type:=getResult.Type, hasErrors)
Copy link
Contributor

@AlekseyTs AlekseyTs Apr 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getResult.Type

It will be good to have a test for a scenario when we are awaiting a Task rather than a Task(Of T). #Closed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also it would be good to test the effect of this change on an await in a Sub expression lambda.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a scenario when we are awaiting a Task rather than a Task(Of T).

I think TestAwaitExpression (first test in that file) covers that.

an await in a Sub expression lambda.

Can you clarify what you'd like this test to verify? Just the IOperation node for the await in statement in lambda, or something else?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you clarify what you'd like this test to verify? Just the IOperation node for the await in statement in lambda, or something else?

Emit, execution, optionally IOperation.

@@ -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
Copy link
Contributor

@AlekseyTs AlekseyTs Apr 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this file doesn't have meaningful changes. Please revert. #Closed

@@ -99,7 +93,6 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Me.F.AssignmentExpression(Me.F.Local(resultTemp, True), rewrittenGetResult),
clearAwaiterTemp,
Me.F.Local(resultTemp, False))

Else
Copy link
Contributor

@AlekseyTs AlekseyTs Apr 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The empty line before Else is intentional. #Closed

@AlekseyTs
Copy link
Contributor

Done with review pass (commit 1)

@jcouv jcouv changed the title Use proper type for BoundAwaitOperator in VB statement Use non-void type for BoundAwaitOperator in VB statement Apr 20, 2023
@jcouv
Copy link
Member Author

jcouv commented Apr 20, 2023

@dotnet/roslyn-compiler for another review. Thanks

@jcouv jcouv requested a review from AlekseyTs April 20, 2023 16:38
]]>.Value

Dim expectedDiagnostics = <![CDATA[
BC30491: Expression does not produce a value.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a benefit in having this error?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we actually want to verify that we can emit and run the code.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This scenario hasn't changed. We already produce an error today, so I'm not sure what you're asking.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This scenario hasn't changed. We already produce an error today, so I'm not sure what you're asking.

I am asking why you are testing this error scenario. An action cannot be awaited, and it really doesn't matter what is in the lambda that was used to create the Action. The error doesn't test anything related to the change you are making.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, unless you have a specific reason to test this error scenario in connection to the change that you are making, consider getting rid of the error and converting the test into a success form (build/execute) similar to the test below.

Public Async Function M() as Task
Dim lambda As Action = Async Sub()
Await M2()'BIND:"Await M2()"
End Sub
Copy link
Contributor

@AlekseyTs AlekseyTs Apr 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't an expression lambda though. And expression lambda would look like

Async Sub() Await M2()

Let's keep this scenario too. #Closed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep this scenario too.

Here I was referring to the body of the lambda rather than to the error.

Await M2()'BIND:"Await M2()"
End Sub

Await lambda()
Copy link
Contributor

@AlekseyTs AlekseyTs Apr 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Await

Let's drop Await here and Async from the M #Closed

@AlekseyTs
Copy link
Contributor

Done with review pass (commit 4)

Copy link
Contributor

@AlekseyTs AlekseyTs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (commit 5)

@jcouv
Copy link
Member Author

jcouv commented Apr 21, 2023

@dotnet/roslyn-compiler for second review. Thanks

@jcouv
Copy link
Member Author

jcouv commented Apr 24, 2023

@dotnet/roslyn-compiler for a second review. Thanks

@jcouv jcouv merged commit 1546e8e into dotnet:main Apr 25, 2023
@jcouv jcouv deleted the await-iop branch April 25, 2023 00:16
@ghost ghost modified the milestones: 17.7, Next Apr 25, 2023
@dibarbet dibarbet modified the milestones: Next, 17.7 P1 Apr 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

IAwaitOperation.Type shouldn't be void for VB when await is bound as statement
4 participants