Sat, 22 Dec 2018 13:10:38 -0800
Added tag jdk8u202-b25 for changeset 15d8c732039b
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * @test /nodynamiccopyright/ |
aoqi@0 | 3 | * @bug 8029718 |
aoqi@0 | 4 | * @summary Should always use lambda body structure to disambiguate overload resolution |
aoqi@0 | 5 | * @compile/fail/ref=MostSpecific09.out -XDrawDiagnostics -XDshouldStopPolicy=ATTR -XDverboseResolution=applicable,success MostSpecific09.java |
aoqi@0 | 6 | */ |
aoqi@0 | 7 | |
aoqi@0 | 8 | class MostSpecific09 { |
aoqi@0 | 9 | |
aoqi@0 | 10 | interface I { |
aoqi@0 | 11 | String xoo(String x); |
aoqi@0 | 12 | } |
aoqi@0 | 13 | |
aoqi@0 | 14 | interface J { |
aoqi@0 | 15 | void xoo(int x); |
aoqi@0 | 16 | } |
aoqi@0 | 17 | |
aoqi@0 | 18 | static void foo(I i) {} |
aoqi@0 | 19 | static void foo(J j) {} |
aoqi@0 | 20 | |
aoqi@0 | 21 | static void moo(I i) {} |
aoqi@0 | 22 | static void moo(J j) {} |
aoqi@0 | 23 | |
aoqi@0 | 24 | void m() { |
aoqi@0 | 25 | foo((x) -> { return x += 1; }); |
aoqi@0 | 26 | foo((x) -> { return ""; }); |
aoqi@0 | 27 | foo((x) -> { System.out.println(""); }); |
aoqi@0 | 28 | foo((x) -> { return ""; System.out.println(""); }); |
aoqi@0 | 29 | foo((x) -> { throw new RuntimeException(); }); |
aoqi@0 | 30 | foo((x) -> { while (true); }); |
aoqi@0 | 31 | |
aoqi@0 | 32 | foo((x) -> x += 1); |
aoqi@0 | 33 | foo((x) -> ""); |
aoqi@0 | 34 | } |
aoqi@0 | 35 | |
aoqi@0 | 36 | /* any return statement that is not in the body of the lambda but in an |
aoqi@0 | 37 | * inner class or another lambda should be ignored for value void compatibility |
aoqi@0 | 38 | * determination. |
aoqi@0 | 39 | */ |
aoqi@0 | 40 | void m1() { |
aoqi@0 | 41 | boolean cond = true; |
aoqi@0 | 42 | foo((x) -> { |
aoqi@0 | 43 | if (cond) { |
aoqi@0 | 44 | return ""; |
aoqi@0 | 45 | } |
aoqi@0 | 46 | System.out.println(""); |
aoqi@0 | 47 | }); |
aoqi@0 | 48 | |
aoqi@0 | 49 | foo((x)->{ |
aoqi@0 | 50 | class Bar { |
aoqi@0 | 51 | String m() { |
aoqi@0 | 52 | return "from Bar.m()"; |
aoqi@0 | 53 | } |
aoqi@0 | 54 | } |
aoqi@0 | 55 | class Boo { |
aoqi@0 | 56 | Bar b = new Bar (){ |
aoqi@0 | 57 | String m() { |
aoqi@0 | 58 | return "from Bar$1.m()"; |
aoqi@0 | 59 | } |
aoqi@0 | 60 | }; |
aoqi@0 | 61 | } |
aoqi@0 | 62 | moo((y) -> { return ""; }); |
aoqi@0 | 63 | return; |
aoqi@0 | 64 | }); |
aoqi@0 | 65 | |
aoqi@0 | 66 | foo((x)->{ |
aoqi@0 | 67 | class Bar { |
aoqi@0 | 68 | void m() {} |
aoqi@0 | 69 | } |
aoqi@0 | 70 | class Boo { |
aoqi@0 | 71 | Bar b = new Bar (){ |
aoqi@0 | 72 | void m() { |
aoqi@0 | 73 | return; |
aoqi@0 | 74 | } |
aoqi@0 | 75 | }; |
aoqi@0 | 76 | } |
aoqi@0 | 77 | moo((y) -> { System.out.println(""); }); |
aoqi@0 | 78 | return ""; |
aoqi@0 | 79 | }); |
aoqi@0 | 80 | } |
aoqi@0 | 81 | } |