langtools/test/tools/javac/lambda/T8024947/PotentiallyAmbiguousWarningTest.java
author vromero
Tue, 15 Oct 2013 21:02:21 +0100
changeset 21025 9d4e765fe447
child 43034 09436b637cb5
permissions -rw-r--r--
8024947: javac should issue the potentially ambiguous overload warning only where the problem appears Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
21025
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
     1
/*
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
     2
 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
     4
 *
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
     7
 * published by the Free Software Foundation.
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
     8
 *
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    13
 * accompanied this code).
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    14
 *
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    18
 *
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    21
 * questions.
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    22
 */
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    23
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    24
/*
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    25
 * @test
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    26
 * @bug 8024947
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    27
 * @summary javac should issue the potentially ambiguous overload warning only
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    28
 * where the problem appears
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    29
 * @compile/fail/ref=PotentiallyAmbiguousWarningTest.out -XDrawDiagnostics -Werror -Xlint:overloads PotentiallyAmbiguousWarningTest.java
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    30
 * @compile PotentiallyAmbiguousWarningTest.java
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    31
 */
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    32
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    33
import java.util.function.*;
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    34
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    35
public interface PotentiallyAmbiguousWarningTest {
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    36
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    37
    //a warning should be fired
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    38
    interface I1 {
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    39
        void foo(Consumer<Integer> c);
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    40
        void foo(IntConsumer c);
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    41
    }
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    42
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    43
    //a warning should be fired
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    44
    class C1 {
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    45
        void foo(Consumer<Integer> c) { }
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    46
        void foo(IntConsumer c) { }
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    47
    }
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    48
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    49
    interface I2 {
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    50
        void foo(Consumer<Integer> c);
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    51
    }
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    52
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    53
    //a warning should be fired, J1 is provoking the issue
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    54
    interface J1 extends I2 {
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    55
        void foo(IntConsumer c);
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    56
    }
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    57
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    58
    //no warning here, the issue is introduced in I1
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    59
    interface I3 extends I1 {}
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    60
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    61
    //no warning here, the issue is introduced in I1. I4 is just overriding an existing method
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    62
    interface I4 extends I1 {
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    63
        void foo(IntConsumer c);
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    64
    }
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    65
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    66
    class C2 {
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    67
        void foo(Consumer<Integer> c) { }
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    68
    }
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    69
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    70
    //a warning should be fired, D1 is provoking the issue
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    71
    class D1 extends C2 {
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    72
        void foo(IntConsumer c) { }
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    73
    }
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    74
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    75
    //a warning should be fired, C3 is provoking the issue
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    76
    class C3 implements I2 {
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    77
        public void foo(Consumer<Integer> c) { }
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    78
        public void foo(IntConsumer c) { }
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    79
    }
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    80
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    81
    //no warning here, the issue is introduced in C1
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    82
    class C4 extends C1 {}
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    83
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    84
    //no warning here, the issue is introduced in C1. C5 is just overriding an existing method
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    85
    class C5 extends C1 {
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    86
        void foo(IntConsumer c) {}
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    87
    }
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    88
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    89
    interface I5<T> {
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    90
        void foo(T c);
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    91
    }
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    92
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    93
    //a warning should be fired, J2 is provoking the issue
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    94
    interface J2 extends I5<IntConsumer> {
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    95
        void foo(Consumer<Integer> c);
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    96
    }
9d4e765fe447 8024947: javac should issue the potentially ambiguous overload warning only where the problem appears
vromero
parents:
diff changeset
    97
}