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