Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions standard/expressions.md
Original file line number Diff line number Diff line change
Expand Up @@ -6408,6 +6408,16 @@ Delegate parse5 = (string s) => int.Parse(s);

A method group has a natural type if all candidate methods (including extension methods) in the method group have a common signature including default values and `params` modifiers.

The following steps are taken to determine if a method group has a natural type; they involve going scope-by-scope and eliminating candidates that cannot succeed as early as possible (just as with overload resolution):

- For each scope, the set of all candidate methods is constructed:
- For the initial scope, methods on the relevant type with arity matching the provided type arguments and satisfying constraints with the provided type arguments are in the set if they are static and the receiver is a type, or if they are non-static and the receiver is a value.
- For subsequent scopes, extension methods in that scope that can be substituted with the provided type arguments and reduced using the value of the receiver while satisfying constraints are in the set:
1. If there are candidates in the given scope, proceed to the next scope.
1. If the signatures of all the candidates do not match, then the method group doesn't have a natural type.
1. Otherwise, the resulting signature is used as the natural type.
- If the scopes are exhausted, then the method group doesn't have a natural type.

```csharp
var read = Console.Read; // Just one overload; Func<int> inferred
var write = Console.Write; // error: multiple overloads, can't choose
Expand Down
Loading