1/*
2 * @test /nodynamiccopyright/
3 * @bug 8024947
4 * @summary javac should issue the potentially ambiguous overload warning only
5 * where the problem appears
6 * @compile/fail/ref=PotentiallyAmbiguousWarningTest.out -XDrawDiagnostics -Werror -Xlint:overloads PotentiallyAmbiguousWarningTest.java
7 */
8
9import java.util.function.*;
10
11public interface PotentiallyAmbiguousWarningTest {
12
13    //a warning should be fired
14    interface I1 {
15        void foo(Consumer<Integer> c);
16        void foo(IntConsumer c);
17    }
18
19    //a warning should be fired
20    class C1 {
21        void foo(Consumer<Integer> c) { }
22        void foo(IntConsumer c) { }
23    }
24
25    interface I2 {
26        void foo(Consumer<Integer> c);
27    }
28
29    //a warning should be fired, J1 is provoking the issue
30    interface J1 extends I2 {
31        void foo(IntConsumer c);
32    }
33
34    //no warning here, the issue is introduced in I1
35    interface I3 extends I1 {}
36
37    //no warning here, the issue is introduced in I1. I4 is just overriding an existing method
38    interface I4 extends I1 {
39        void foo(IntConsumer c);
40    }
41
42    class C2 {
43        void foo(Consumer<Integer> c) { }
44    }
45
46    //a warning should be fired, D1 is provoking the issue
47    class D1 extends C2 {
48        void foo(IntConsumer c) { }
49    }
50
51    //a warning should be fired, C3 is provoking the issue
52    class C3 implements I2 {
53        public void foo(Consumer<Integer> c) { }
54        public void foo(IntConsumer c) { }
55    }
56
57    //no warning here, the issue is introduced in C1
58    class C4 extends C1 {}
59
60    //no warning here, the issue is introduced in C1. C5 is just overriding an existing method
61    class C5 extends C1 {
62        void foo(IntConsumer c) {}
63    }
64
65    interface I5<T> {
66        void foo(T c);
67    }
68
69    //a warning should be fired, J2 is provoking the issue
70    interface J2 extends I5<IntConsumer> {
71        void foo(Consumer<Integer> c);
72    }
73}
74