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

Infer delegate types with -langversion:10 (and above) only #55232

Merged
merged 2 commits into from
Jul 29, 2021

Conversation

cston
Copy link
Member

@cston cston commented Jul 29, 2021

Do not infer delegate types for lambda expressions and method groups when compiling with -langversion:9 and earlier, to restore the binding behavior from C#9 for those cases.

This matches the behavior in 16.11 where inferring delegate types is conditional on -langversion (see #53241). That behavior was reverted in commit 7d461ed for earlier 17.0 previews, and is now re-applied.

See LDM notes: lambda-conversion-to-systemdelegate.

@cston cston requested a review from a team as a code owner July 29, 2021 17:42
@cston cston added this to the 17.0.P3 milestone Jul 29, 2021
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 1)

@jcouv jcouv self-assigned this Jul 29, 2021
@@ -1358,12 +1358,9 @@ static void Main()
// (6,30): error CS0034: Operator '==' is ambiguous on operands of type '<null>' and 'default'
// System.Console.Write((null, () => 1) == (default, default));
Diagnostic(ErrorCode.ERR_AmbigBinaryOps, "(null, () => 1) == (default, default)").WithArguments("==", "<null>", "default").WithLocation(6, 30),
// (6,37): error CS8773: Feature 'inferred delegate type' is not available in C# 9.0. Please use language version 10.0 or greater.
// (6,30): error CS0019: Operator '==' cannot be applied to operands of type 'lambda expression' and 'default'
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if later on (i.e. not in this PR/release) it will be practical to devise some way to still give LangVersion diagnostics. For example, by checking again at the point we give a conversion error if a valid conversion "would have" existed in the later language version.

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 2)

@jcouv
Copy link
Member

jcouv commented Jul 29, 2021

Approved to merge whenever CI is green

@cston cston merged commit a429a88 into dotnet:release/dev17.0 Jul 29, 2021
@cston cston deleted the revert-revert-53241 branch July 29, 2021 22:50
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.

3 participants