Skip to content

Commit

Permalink
Adjust dynamic binding rules for a situation of a single applicable c…
Browse files Browse the repository at this point in the history
…andidate.

Meant to mitigate breaking changes like dotnet/roslyn#72750.
  • Loading branch information
AlekseyTs committed Apr 1, 2024
1 parent 697bb62 commit 21b950b
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions proposals/params-collections.md
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,30 @@ If only a single candidate passes the test, the invocation of the candidate is s
- the candidate is either not generic, or its type arguments are explicitly specified;
- there is no ambiguity between normal and expanded forms of the candidate that cannot be resolved at compile time.

In this case, if the single candidate is not a local function and returns a value (doesn't have type `void`) and there is an
implicit conversion from result type to `dynamic`, then result of the invocation is the returned value converted to `dynamic`.
For example:
```csharp
unsafe public class C
{
public static void Main()
{
dynamic d = 1;
var a = Test1(d); // error CS0815: Cannot assign void to an implicitly-typed variable
var b = Test2(d); // void*, there is no implicit conversion to dynamic
var c = Test3(d); // dynamic
c.InvokeOnDynamic(); // No error
var d = test4(d); // int
static int test4(int x) => x;
}

static void Test1(int x) {}
static void* Test2(int x) => null;
static int Test3(int x) => x;
}
```

Otherwise, the *invocation_expression* is dynamically bound.
- If only a single candidate passed the test above:
- if that candidate is a local function, a compile-time error occurs;
Expand Down

0 comments on commit 21b950b

Please sign in to comment.