Skip to content

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

Merged
cston merged 2 commits intodotnet:release/dev17.0from
cston:revert-revert-53241
Jul 29, 2021
Merged

Infer delegate types with -langversion:10 (and above) only#55232
cston merged 2 commits intodotnet:release/dev17.0from
cston:revert-revert-53241

Conversation

@cston
Copy link
Contributor

@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
@ghost ghost added the Area-Compilers label Jul 29, 2021
@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
// 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
Member

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