Skip to content

Commit 45a1455

Browse files
authored
Only allow static methods for applicable members (#3281)
* 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.
1 parent a6c3852 commit 45a1455

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

proposals/function-pointers.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,8 @@ In an unsafe context, a method `M` is compatible with a function pointer type `F
175175
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.
176176
- A single method `M` is selected corresponding to a method invocation of the form `E(A)` with the following modifications:
177177
- 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`.
178-
- 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.
178+
- The candidate methods are only those methods that are applicable in their normal form, not those applicable in their expanded form.
179+
- The candidate methods are only those methods that are static.
179180
- 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.
180181
- The selected method `M` must be compatible (as defined above) with the function pointer type `F`. Otherwise, a compile-time error occurs.
181182
- The result of the conversion is a function pointer of type `F`.

0 commit comments

Comments
 (0)