[Proposal]: Type Parameter Inference from Constraints
Author: 333fredCreated Jun 17, 2025Updated Aug 13, 2026
LabelsProposal champion
Type Parameter Inference from Constraints
- Specification: https://github.com/dotnet/csharplang/pull/9455
- Discussion: https://github.com/dotnet/csharplang/discussions/9454
- Implementation: https://github.com/dotnet/roslyn/pull/84655
Summary
Allow type inference to succeed in overload resolution scenarios by promoting generic constraints of inferred type parameters to "fake arguments" during type inference, enabling the bounds of type variables to participate in the inference process. An example is:
List<int> l = [1, 2, 3];
M(l); // Today: TElement cannot be inferred. With this proposal, successful call.
void M<TEnumerable, TElement>(TEnumerable t) where TEnumerable : IEnumerable<TElement>
{
Console.WriteLine(string.Join(",", t));
}Design meetings
- https://github.com/dotnet/csharplang/blob/main/meetings/2025/LDM-2025-06-30.md#type-parameter-inference-from-constraints
- https://github.com/dotnet/csharplang/blob/main/meetings/2025/LDM-2025-08-18.md#type-inference
- https://github.com/dotnet/csharplang/blob/main/meetings/2026/LDM-2026-08-12.md#type-parameter-inference-from-constraints-implementation-review
Source: dotnet/csharplang