MostSpecific09.java revision 3858:6cb046ee1000
1/*
2 * @test /nodynamiccopyright/
3 * @bug 8029718 8065800
4 * @summary Should always use lambda body structure to disambiguate overload resolution
5 * @compile/fail/ref=MostSpecific09.out -XDrawDiagnostics --should-stop:at=ATTR --debug:verboseResolution=applicable,success MostSpecific09.java
6 */
7
8class MostSpecific09 {
9
10    interface I {
11        String xoo(String x);
12    }
13
14    interface J {
15        void xoo(int x);
16    }
17
18    static void foo(I i) {}
19    static void foo(J j) {}
20
21    static void moo(I i) {}
22    static void moo(J j) {}
23
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); });
31
32        foo((x) -> x += 1);
33        foo((x) -> "");
34    }
35
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        });
48
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        });
65
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}
82