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

ref/out parameters in async methods with AsyncMethodBuilderAttribute #60332

Closed
ufcpp opened this issue Mar 23, 2022 · 1 comment · Fixed by #65352
Closed

ref/out parameters in async methods with AsyncMethodBuilderAttribute #60332

ufcpp opened this issue Mar 23, 2022 · 1 comment · Fixed by #65352
Assignees
Labels
Area-Compilers Bug Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented
Milestone

Comments

@ufcpp
Copy link
Contributor

ufcpp commented Mar 23, 2022

Version Used:

VS 15.1.2
.NET SDK 6.0.201
C# Tools 4.1.0-5.22165.10+e555772db77ca828b02b4bd547c318387f11d01f

Steps to Reproduce:

using System.Runtime.CompilerServices;

int x = 1;
await m0(ref x, out var y0);
await m1(ref x, out var y1);

static async ValueTask m0(ref int x, out int y) // Error CS1988
{
    await Task.Delay(1000);
    y = x * x;
    x = y * y;
}

[AsyncMethodBuilder(typeof(PoolingAsyncValueTaskMethodBuilder))]
static async ValueTask m1(ref int x, out int y) // No error
{
    await Task.Delay(1000);
    y = x * x;
    x = y * y;
}

Thanks to @neuecc
https://twitter.com/neuecc/status/1506262798946701314

Expected Behavior:

CS 1988 Error on m1.

Actual Behavior:

No error on m1.

As a side note, not only PoolingAsyncValueTaskMethodBuilder but also any builders cause the same behavior.

[AsyncMethodBuilder(typeof(MyAsyncMethodBuilder))]
static async ValueTask m2(ref int x, out int y) // No error
{
    await Task.Delay(1000);
    y = x * x;
    x = y * y;
}

public struct MyAsyncMethodBuilder
{
    public ValueTask Task { get; }
    public static MyAsyncMethodBuilder Create() => default;
    public void AwaitOnCompleted<TAwaiter, TStateMachine>(ref TAwaiter awaiter, ref TStateMachine stateMachine)
        where TAwaiter : INotifyCompletion
        where TStateMachine : IAsyncStateMachine
    { }
    public void AwaitUnsafeOnCompleted<TAwaiter, TStateMachine>(ref TAwaiter awaiter, ref TStateMachine stateMachine)
        where TAwaiter : ICriticalNotifyCompletion
        where TStateMachine : IAsyncStateMachine
    { }
    public void SetException(Exception exception) { }
    public void SetResult() { }
    public void SetStateMachine(IAsyncStateMachine stateMachine) { }
    public void Start<TStateMachine>(ref TStateMachine stateMachine) where TStateMachine : IAsyncStateMachine { }
}
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Mar 23, 2022
@jcouv jcouv self-assigned this Mar 23, 2022
@jcouv jcouv added Bug and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Mar 23, 2022
@jcouv jcouv added this to the 17.2 milestone Mar 23, 2022
@jinujoseph jinujoseph modified the milestones: 17.2, 17.3 May 5, 2022
@jcouv jcouv modified the milestones: 17.3, 17.5 Sep 30, 2022
@arunchndr arunchndr modified the milestones: 17.5, 17.5 P1 Oct 3, 2022
@jcouv jcouv added 3 - Working 4 - In Review A fix for the issue is submitted for review. and removed 3 - Working labels Nov 11, 2022
@jcouv
Copy link
Member

jcouv commented Nov 11, 2022

Thanks @neuecc @ufcpp for reporting this! Fix is pending review

@jcouv jcouv added Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented and removed 4 - In Review A fix for the issue is submitted for review. labels Nov 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Bug Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants