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

Rectify async checks logic in presence of AsyncMethodBuilder attribute #65352

Merged
merged 2 commits into from
Nov 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1102,7 +1102,7 @@ protected void AsyncMethodChecks(bool verifyReturnType, Location errorLocation,

if (this.HasAsyncMethodBuilderAttribute(out _))
{
hasErrors |= MessageID.IDS_AsyncMethodBuilderOverride.CheckFeatureAvailability(diagnostics, this.DeclaringCompilation, errorLocation);
MessageID.IDS_AsyncMethodBuilderOverride.CheckFeatureAvailability(diagnostics, this.DeclaringCompilation, errorLocation);
}

// Avoid checking attributes on containing types to avoid a potential cycle when a lambda
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1594,5 +1594,72 @@ public static void M(MyResult r)
compilation.VerifyDiagnostics();
CompileAndVerify(compilation, verify: Verification.FailsILVerify, expectedOutput: "3");
}

[Theory, CombinatorialData, WorkItem(60332, "https://github.com/dotnet/roslyn/issues/60332")]
public void RefParameterOnMethodWithAsyncMethodBuilderAttribute(bool useCSharp9)
{
var source = """
using System.Runtime.CompilerServices;
using System.Threading.Tasks;

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) // 1
{
await Task.Delay(1000);
y = x * x;
x = y * y;
}

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

var compilation = CreateCompilation(source, parseOptions: useCSharp9 ? TestOptions.Regular9 : TestOptions.Regular10, targetFramework: TargetFramework.Net70);
Copy link
Contributor

@AlekseyTs AlekseyTs Nov 11, 2022

Choose a reason for hiding this comment

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

Regular10

Regular? #ByDesign

Copy link
Member Author

Choose a reason for hiding this comment

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

I think Regular10 is better. That's what we usually do for explicit LangVer tests that verify the boundary when the feature was introduced.

if (useCSharp9)
{
compilation.VerifyDiagnostics(
// (8,35): error CS1988: Async methods cannot have ref, in or out parameters
// static async ValueTask m0(ref int x, out int y) // 1
Diagnostic(ErrorCode.ERR_BadAsyncArgType, "x").WithLocation(8, 35),
// (8,46): error CS1988: Async methods cannot have ref, in or out parameters
// static async ValueTask m0(ref int x, out int y) // 1
Diagnostic(ErrorCode.ERR_BadAsyncArgType, "y").WithLocation(8, 46),
// (16,24): error CS8773: Feature 'async method builder override' is not available in C# 9.0. Please use language version 10.0 or greater.
// static async ValueTask m1(ref int x, out int y) // 2
Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion9, "m1").WithArguments("async method builder override", "10.0").WithLocation(16, 24),
// (16,35): error CS1988: Async methods cannot have ref, in or out parameters
// static async ValueTask m1(ref int x, out int y) // 2
Diagnostic(ErrorCode.ERR_BadAsyncArgType, "x").WithLocation(16, 35),
// (16,46): error CS1988: Async methods cannot have ref, in or out parameters
// static async ValueTask m1(ref int x, out int y) // 2
Diagnostic(ErrorCode.ERR_BadAsyncArgType, "y").WithLocation(16, 46)
);
}
else
{
compilation.VerifyDiagnostics(
// (8,35): error CS1988: Async methods cannot have ref, in or out parameters
// static async ValueTask m0(ref int x, out int y) // 1
Diagnostic(ErrorCode.ERR_BadAsyncArgType, "x").WithLocation(8, 35),
// (8,46): error CS1988: Async methods cannot have ref, in or out parameters
// static async ValueTask m0(ref int x, out int y) // 1
Diagnostic(ErrorCode.ERR_BadAsyncArgType, "y").WithLocation(8, 46),
// (16,35): error CS1988: Async methods cannot have ref, in or out parameters
// static async ValueTask m1(ref int x, out int y) // 2
Diagnostic(ErrorCode.ERR_BadAsyncArgType, "x").WithLocation(16, 35),
// (16,46): error CS1988: Async methods cannot have ref, in or out parameters
// static async ValueTask m1(ref int x, out int y) // 2
Diagnostic(ErrorCode.ERR_BadAsyncArgType, "y").WithLocation(16, 46)
);
}
}
}
}