Sat, 04 Aug 2018 12:55:17 +0100
Merge
1 /*
2 * @test /nodynamiccopyright/
3 * @bug 8026231
4 * @summary Look at 'static' flag when checking method references
5 * @compile/fail/ref=MethodReference73.out -XDrawDiagnostics MethodReference73.java
6 */
8 public class MethodReference73 {
10 interface SAM {
11 void m(MethodReference73 rec, String x);
12 }
14 void m1(MethodReference73 rec, String x) {}
15 static void m1(MethodReference73 rec, Object x) {}
16 void m1(String x) {}
18 static void m2(MethodReference73 rec, String x) {}
19 void m2(Object x) {}
20 static void m2(String x) {}
22 static void m3(MethodReference73 rec, String x) {}
23 void m3(String x) {}
25 void m4(MethodReference73 rec, String x) {}
26 static void m4(MethodReference73 rec, Object x) {}
27 static void m4(String x) {}
28 void m4(Object x) {}
30 static void m5(MethodReference73 rec, String x) {}
31 static void m5(String x) {}
33 static void m6(MethodReference73 rec, String x) {}
34 void m6(String x, int i) {}
36 void m7(MethodReference73 rec, String x) {}
37 void m7(String x) {}
39 static void m8(MethodReference73 rec, String x, int i) {}
40 void m8(String x) {}
42 void m9(MethodReference73 rec, String x) {}
43 static void m9(MethodReference73 rec, Object x) {}
44 static void m9(String x) {}
46 void m10(MethodReference73 rec, String x) {}
47 static void m10(MethodReference73 rec, Object x) {}
48 void m10(String x, int i) {}
50 void m11(MethodReference73 rec, String x) {}
51 void m11(Object x) {}
52 static void m11(String x) {}
54 static void m12(MethodReference73 rec, String x, int i) {}
55 void m12(Object x) {}
56 static void m12(String x) {}
58 void m13(MethodReference73 rec, String x) {}
59 void m13(String x, int i) {}
61 static void m14(MethodReference73 rec, String x, int i) {}
62 static void m14(String x) {}
64 void m15(MethodReference73 rec, String x) {}
65 static void m15(String x) {}
67 static void m16(MethodReference73 rec, String x, int i) {}
68 void m16(String x, int i) {}
70 /** For method references with a type selector two searches are performed.
71 * Each of them may yield one of the following results:
72 * I) a good match
73 * II) a bad match more specific than a good match
74 * III) a bad match with no good matches
75 * IV) no applicable method found
76 *
77 * Whether a match is considered to be good or not depends on the staticness
78 * of the matched method. The expected result of the first search is a static
79 * method. The expected result of the second search is an instance method.
80 *
81 * If the most specific method has the wrong staticness but there is an
82 * applicable method with the right staticness then we have the (II) case.
83 * The (III) case is reserved for those cases when the most specific method
84 * has the wrong staticness but there is no applicable method with the right
85 * staticness.
86 */
88 static void test() {
89 SAM s1 = MethodReference73::m1; //(II, I) ambiguous
90 SAM s2 = MethodReference73::m2; //(I, II) ambiguous
91 SAM s3 = MethodReference73::m3; //(I, I) ambiguous
92 SAM s4 = MethodReference73::m4; //(II, II) ambiguous
94 SAM s5 = MethodReference73::m5; //(I, III) first search's result gets selected
95 SAM s6 = MethodReference73::m6; //(I, IV) first search's result gets selected
97 SAM s7 = MethodReference73::m7; //(III, I) second search's result gets selected
98 SAM s8 = MethodReference73::m8; //(IV, I) second search's result gets selected
100 SAM s9 = MethodReference73::m9; //(II, III) method matched by first search has the wrong staticness
101 SAM s10 = MethodReference73::m10; //(II, IV) method matched by first search has the wrong staticness
102 SAM s11 = MethodReference73::m11; //(III, II) method matched by second search has the wrong staticness
103 SAM s12 = MethodReference73::m12; //(IV, II) method matched by second search has the wrong staticness
104 SAM s13 = MethodReference73::m13; //(III, IV) method matched by first search has the wrong staticness
105 SAM s14 = MethodReference73::m14; //(IV, III) method matched by second search has the wrong staticness
106 SAM s15 = MethodReference73::m15; //(III, III) method matched by first search has the wrong staticness
108 SAM s16 = MethodReference73::m16; //(IV, IV) incompatible types, invalid method reference
109 }
110 }