Skip to content

Commit

Permalink
Only allow static methods for applicable members (#3281)
Browse files Browse the repository at this point in the history
* Only allow static methods for applicable members

This fixes a very similar problem to #3277, where this code is unable to be resolved:
```cs
interface I1{}
interface I2{}

public unsafe class C : I1, I2 {
    void M(I1 i) {}
    static void M(I2 i) {}
    public void M1() {
        delegate*<C, void> a = M; // Ambiguous because both M's are applicable
    }
}
```
With this change, the instance method M is not applicable, so there is no ambiguity.
  • Loading branch information
333fred authored Mar 19, 2020
1 parent a6c3852 commit 45a1455
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion proposals/function-pointers.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ In an unsafe context, a method `M` is compatible with a function pointer type `F
In an unsafe context, an implicit conversion exists from an address-of expression whose target is a method group `E` to a compatible function pointer type `F` if `E` contains at least one method that is applicable in its normal form to an argument list constructed by use of the parameter types and modifiers of `F`, as described in the following.
- A single method `M` is selected corresponding to a method invocation of the form `E(A)` with the following modifications:
- The arguments list `A` is a list of expressions, each classified as a variable and with the type and modifier (`ref`, `out`, or `in`) of the corresponding _formal\_parameter\_list_ of `D`.
- The candidate methods are only those methods that are only those methods that are applicable in their normal form, not those applicable in their expanded form.
- The candidate methods are only those methods that are applicable in their normal form, not those applicable in their expanded form.
- The candidate methods are only those methods that are static.
- If the algorithm of Method invocations produces an error, then a compile-time error occurs. Otherwise, the algorithm produces a single best method `M` having the same number of parameters as `F` and the conversion is considered to exist.
- The selected method `M` must be compatible (as defined above) with the function pointer type `F`. Otherwise, a compile-time error occurs.
- The result of the conversion is a function pointer of type `F`.
Expand Down

0 comments on commit 45a1455

Please sign in to comment.