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

Allow ref enumerators in async/iterator methods #74800

Merged
merged 4 commits into from
Sep 2, 2024

Conversation

jjonescz
Copy link
Member

Fixes #74793.
Related to test plan #72662.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Aug 19, 2024
@jjonescz jjonescz force-pushed the RefInAsync-08-Foreach branch from fc2395c to f72e4b2 Compare August 19, 2024 14:26
@jjonescz jjonescz force-pushed the RefInAsync-08-Foreach branch from f72e4b2 to 05aa011 Compare August 19, 2024 14:32
@jjonescz jjonescz marked this pull request as ready for review August 19, 2024 15:50
@jjonescz jjonescz requested a review from a team as a code owner August 19, 2024 15:50
@jjonescz jjonescz requested a review from cston August 22, 2024 09:27
@jjonescz
Copy link
Member Author

@dotnet/roslyn-compiler for reviews, thanks

);

comp2 = CreateCompilation(src1 + src2, targetFramework: s_targetFrameworkSupportingByRefLikeGenerics, parseOptions: TestOptions.Regular12);
comp2.VerifyEmitDiagnostics(
// (14,24): error CS9202: Feature 'ref struct interfaces' is not available in C# 12.0. Please use language version 13.0 or greater.
// public ref struct S2 : IAsyncDisposable
Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion12, "IAsyncDisposable").WithArguments("ref struct interfaces", "13.0").WithLocation(14, 24),
// (40,15): error CS8344: foreach statement cannot operate on enumerators of type 'S2' in async or iterator methods because 'S2' is a ref struct or a type parameter that allows ref struct.
// (40,15): error CS9202: Feature 'ref and unsafe in async and iterator methods' is not available in C# 12.0. Please use language version 13.0 or greater.
Copy link
Member

Choose a reason for hiding this comment

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

Diagnostic clarity and not directly related to this PR: is it intentional that when we report the LangVer error we no longer report CS4007?
This seems rather unfriendly (user gets a bad surprise after following our advice to upgrade LangVer).

Copy link
Member Author

@jjonescz jjonescz Aug 28, 2024

Choose a reason for hiding this comment

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

Yes, that's a pre-existing issue. The CS4007 is reported during emit, so we never get to report it when we report other binding-time errors. It's also a pre-existing error (so we cannot replace it with a LangVersion error) but perhaps we could detect just the new scenarios and report a LangVersion error for them in the emit phase instead (I'm not sure how feasible that would be).

(Btw, there is also a tracking issue for a similar problem for unsafe: #73280 - it's part of the same feature but the issue currently only talks about different diagnostics.)

Copy link
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

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

LGTM Thanks (iteration 3)

@jcouv jcouv self-assigned this Aug 27, 2024
@jcouv
Copy link
Member

jcouv commented Aug 27, 2024

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

1 similar comment
@jcouv
Copy link
Member

jcouv commented Aug 30, 2024

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

@jjonescz jjonescz enabled auto-merge (squash) September 2, 2024 08:54
@jjonescz jjonescz merged commit 935befe into dotnet:main Sep 2, 2024
24 checks passed
@jjonescz jjonescz deleted the RefInAsync-08-Foreach branch September 2, 2024 10:55
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Sep 2, 2024
@akhera99 akhera99 modified the milestones: Next, 17.12 P3 Sep 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Feature - Ref/Unsafe in Iterators/Async untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CS8344 error even with C# 13 (ref in iterators/async)
4 participants