dotnet / dotnet/csharplang

[Proposal]: Type inference using method group natural type

Open
#9,007 0 comments 0 reactions 1 assignee Claimed by @jcouv View on GitHub
Proposal champion
Dominant language
C#
Stars
12.7k
Forks
1.1k
Avg merge
11h 1m
Merged PRs (30d)
3

Description

# Type inference using method group natural type

* Specification: https://github.com/dotnet/csharplang/pull/10239
* Discussion: https://github.com/dotnet/csharplang/discussions/9006

## Summary
[summary]: #summary

It allows the natural type of a method group to contribute to method type inference, so scenarios like the following can work:

```
Test(IsEven); // Error CS0411 The type arguments for method 'Program.Test(Func)' cannot be inferred from the usage. Try specifying the type arguments explicitly.

partial class Program
{
public static bool IsEven(int x) => x % 2 == 0;
public static void Test(Func predicate) { }
}
```

## Design meetings

- https://github.com/dotnet/csharplang/blob/main/meetings/2024/LDM-2024-09-04.md#type-inference-using-method-group-natural-type

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.