-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Implement type parameter inference from constraints #84655
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
Open
agocke
wants to merge
11
commits into
dotnet:main
Choose a base branch
from
agocke:infer-generic-constraints
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
2bf7cb3
Implement type parameter inference from constraints
agocke 80f7ea4
Potential fix for pull request finding
agocke cb4bb24
Apply batched suggestions from code review
agocke 5cde083
Make constraint inference order-independent
agocke 1894c2c
Align constraint inference terminology
agocke 486ddea
Update src/Compilers/CSharp/Portable/Binder/Semantics/OverloadResolut…
agocke 3d83839
Merge branch 'main' into infer-generic-constraints
agocke c17be47
Move constraint inference tests to CSharp16
agocke 59eb275
Document constraint inference breaking change
agocke 4212a5e
Remove trailing whitespace from feature gate
agocke 40476de
Fix copilot mistakes
agocke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
docs/compilers/CSharp/compiler-breaking-changes-dotnet-12.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| # Breaking changes in Roslyn after .NET 11.0.100 through .NET 12.0.100 | ||
|
|
||
| This document lists known breaking changes in Roslyn after .NET 11 general release (.NET SDK version 11.0.100) through .NET 12 general release (.NET SDK version 12.0.100). | ||
|
|
||
| ## Type parameter inference considers generic constraints | ||
|
|
||
| ***Introduced in .NET 12*** | ||
|
|
||
| In C# 16, method type inference can infer type parameters that occur only in the constraints of other inferred type parameters. As a result, a generic method that was previously excluded from overload resolution may become applicable. This can change the selected overload, introduce an ambiguity, or produce a more specific diagnostic from the newly applicable candidate. | ||
|
|
||
| For example, the following call previously selected the non-generic overload because `U` could not be inferred. It now selects the generic overload because `T` is fixed to `string` and `U` is then inferred as `char` from the `IEnumerable<U>` constraint. | ||
|
|
||
| ```cs | ||
| using System; | ||
| using System.Collections.Generic; | ||
|
|
||
| static void M(object value) => Console.WriteLine("non-generic"); | ||
| static void M<T, U>(T value) where T : IEnumerable<U> => Console.WriteLine("generic"); | ||
|
|
||
| M("test"); // C# 15: "non-generic"; C# 16: "generic" | ||
| ``` | ||
|
|
||
| To preserve the previous overload selection, explicitly convert the argument to the intended parameter type: | ||
|
|
||
| ```cs | ||
| M((object)"test"); // "non-generic" | ||
| ``` | ||
|
|
||
| See [the type parameter inference from constraints proposal](https://github.com/dotnet/csharplang/issues/9453) and [the Roslyn implementation](https://github.com/dotnet/roslyn/pull/84655). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This guidance seems incorrect? To test the gate, you want to test across N and RegularNext.