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