changeset 1265:f5dbd6895994

7157798: Add 6 test scenarios for testing inheritance of multiple same-name methods from mulitple interfaces Reviewed-by: mcimadamore Contributed-by: sue.wei@oracle.com
author jjh
date Mon, 21 May 2012 16:10:14 -0700
parents 885806e74240
children f43aded513e7
files test/tools/javac/generics/rawOverride/7157798/Test1.java test/tools/javac/generics/rawOverride/7157798/Test2.java test/tools/javac/generics/rawOverride/7157798/Test3.java test/tools/javac/generics/rawOverride/7157798/Test3.out test/tools/javac/generics/rawOverride/7157798/Test4.java test/tools/javac/generics/rawOverride/7157798/Test4.out
diffstat 6 files changed, 270 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/generics/rawOverride/7157798/Test1.java	Mon May 21 16:10:14 2012 -0700
@@ -0,0 +1,116 @@
+/*
+ * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug      7062745 7157798
+ * @summary  Test inheritance of same-name methods from mulitple interfaces
+             when the methods have compatible return types
+ * @compile  Test1.java
+ */
+
+import java.util.*;
+
+interface A { List<Number> getList(); }
+interface B { List getList(); }
+
+interface AB extends A, B {} //return type: List<Number>
+
+interface C<T> { List<T> getList(); }
+
+interface BC<T> extends B, C<T> {} //return type: List<T>
+
+interface D { Number m(); }
+interface E { Double m(); }
+
+interface DE extends D, E {} //return type: Double
+
+interface F { ArrayList getList(); }
+interface G { Collection getList(); }
+
+interface AG extends A, G{}; //return type: List<Number>
+
+interface CF<T> extends C<T>, F {} //return type: ArrayList
+
+interface CG<T> extends C<T>, G {} //return type: List<T>
+
+interface H<T> { Iterable<T> getList(); }
+
+interface CH<T> extends C<T>, H<T> {} //return type: List<T>
+
+interface CFGH<T> extends C<T>, F, G, H<T> {} //return type: ArrayList
+
+
+class Test1 {
+
+    //raw and typed return types:
+    void test(AB ab) {
+        Number n = ab.getList().get(1);
+    }
+
+    void test(BC<String> bc) {
+        String s = bc.getList().get(1);
+    }
+
+    void testRaw(BC bc) {
+        List list = bc.getList();
+    }
+
+    void testWildCard(BC<?> bc) {
+        List<?> list = bc.getList();
+    }
+
+    <T> void testGeneric(BC<T> bc) {
+        T t = bc.getList().get(1);
+    }
+
+    //covariant return:
+    void test(DE de) {
+        Double d = de.m();
+    }
+
+    //mixed:
+    void test(AG ag) {
+        Number n = ag.getList().get(0);
+    }
+
+    void test(CF<Integer> cf) {
+        ArrayList list = cf.getList();
+    }
+
+    void test(CG<String> cg) {
+        String s = cg.getList().get(0);
+    }
+
+    void test(CH<String> ch) {
+        String s = ch.getList().get(0);
+    }
+
+    void test(CFGH<Double> cfgh) {
+        ArrayList list = cfgh.getList();
+    }
+
+    void testWildCard(CFGH<?> cfgh) {
+        ArrayList list = cfgh.getList();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/generics/rawOverride/7157798/Test2.java	Mon May 21 16:10:14 2012 -0700
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug      7062745 7157798
+ * @summary  Test inheritance of same-name methods from multiple interfaces
+             when the methods have compatible parameter types and return types
+ * @compile  Test2.java
+ */
+
+import java.util.*;
+
+interface A { void m(Map map); }
+interface B { void m(Map<Number, String> map); }
+
+interface AB extends A, B {} //paramter type: Map<Number, String>
+
+interface C<K, V> { List<V> getList(Map<K, V> map); }
+interface D { ArrayList getList(Map map); }
+
+interface CD<K, V> extends C<K, V>, D {} //paramter type: Map<K, V>
+
+interface E<T> { T get(List<?> list); }
+interface F<T> { T get(List list); }
+
+interface EF<T1, T2 extends T1> extends E<T1>, F<T2> {} //parameter type: List<?>
+
+class Test2 {
+
+    //compatible parameter types:
+    void test(AB ab) {
+        ab.m(new HashMap<Number, String>());
+    }
+
+    //compatible parameter types and return types:
+    void testRaw(CD cd) { //return type: ArrayList
+        ArrayList al = cd.getList(new HashMap());
+    }
+
+    <K, V> void testGeneric(CD<K, V> cd) { //return type: List<V>
+        V v = cd.getList(new HashMap<K, V>()).get(0);
+    }
+
+    void test(CD<Number, String> cd) { //return type: List<String>
+        String s = cd.getList(new HashMap<Number, String>()).get(0);
+    }
+
+    void test(EF<Number, Integer> ef) { //return type: Number
+        Number n = ef.get(new ArrayList<Integer>());
+    }
+
+    <T, U extends T> void testGeneric(EF<T, U> ef) { //return type: T
+        T t = ef.get(new ArrayList<U>());
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/generics/rawOverride/7157798/Test3.java	Mon May 21 16:10:14 2012 -0700
@@ -0,0 +1,37 @@
+/**
+ * @test     /nodynamiccopyright/
+ * @bug      7062745 7157798
+ * @summary  Negative test of conflicting same-name methods inherited from multiple interfaces when return type not compatible
+ * @compile/fail/ref=Test3.out -Werror -Xlint:unchecked -XDrawDiagnostics Test3.java
+ */
+
+import java.util.List;
+import java.io.Serializable;
+
+interface A { int m(); }
+interface B { Integer m(); }
+
+interface AB extends A, B {} //error
+
+interface C { List<Integer> m(); }
+interface D { List<Number> m(); }
+
+interface CD extends C, D {} //error
+
+interface E<T> { T m(); }
+interface F<T> { T m(); }
+interface G { Serializable m(); }
+
+interface BE extends B, E<Number> {} //ok, covariant return
+
+interface BE2<T> extends B, E<T> {} //error
+
+interface EF<T> extends E<T>, F<T> {} //ok
+
+interface EF2<U, V extends U> extends E<U>, F<V> {} //ok, covariant return
+
+interface EF3<U, V> extends E<U>, F<V> {} //error
+
+interface EG<T extends Number> extends E<T>, G {} //ok
+
+interface EFG<U extends Serializable, V extends Serializable> extends E<U>, F<V>, G {} //error
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/generics/rawOverride/7157798/Test3.out	Mon May 21 16:10:14 2012 -0700
@@ -0,0 +1,6 @@
+Test3.java:14:1: compiler.err.types.incompatible.diff.ret: B, A, m()
+Test3.java:19:1: compiler.err.types.incompatible.diff.ret: D, C, m()
+Test3.java:27:1: compiler.err.types.incompatible.diff.ret: E<T>, B, m()
+Test3.java:33:1: compiler.err.types.incompatible.diff.ret: F<V>, E<U>, m()
+Test3.java:37:1: compiler.err.types.incompatible.diff.ret: F<V>, E<U>, m()
+5 errors
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/generics/rawOverride/7157798/Test4.java	Mon May 21 16:10:14 2012 -0700
@@ -0,0 +1,29 @@
+/**
+ * @test     /nodynamiccopyright/
+ * @bug      7062745 7157798
+ * @summary  Negative test of conflicting same-name methods inherited from multiple interfaces when parameter types not compatible
+ * @compile/fail/ref=Test4.out -Werror -Xlint:unchecked -XDrawDiagnostics Test4.java
+ */
+
+import java.util.Set;
+import java.util.HashSet;
+
+interface A { void m(Set<Integer> s); }
+interface B { void m(Set<String> s); }
+interface C { void m(Set<?> s); }
+
+interface AB extends A, B {} //error
+
+interface AC extends A, C {} //error
+
+interface D<T> { void m(Set<T> s); }
+
+interface AD extends A, D<Integer> {} //OK
+
+interface AD2 extends A, D<Number> {} //error
+
+interface CD<T> extends C, D<T> {} //error
+
+interface E { <T> void m(Set<T> s); }
+
+interface DE<T> extends D<T>, E {} //error
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/generics/rawOverride/7157798/Test4.out	Mon May 21 16:10:14 2012 -0700
@@ -0,0 +1,6 @@
+Test4.java:15:1: compiler.err.name.clash.same.erasure.no.override: m(java.util.Set<java.lang.String>), B, m(java.util.Set<java.lang.Integer>), A
+Test4.java:17:1: compiler.err.name.clash.same.erasure.no.override: m(java.util.Set<?>), C, m(java.util.Set<java.lang.Integer>), A
+Test4.java:23:1: compiler.err.name.clash.same.erasure.no.override: m(java.util.Set<T>), D, m(java.util.Set<java.lang.Integer>), A
+Test4.java:25:1: compiler.err.name.clash.same.erasure.no.override: m(java.util.Set<T>), D, m(java.util.Set<?>), C
+Test4.java:29:1: compiler.err.name.clash.same.erasure.no.override: <T>m(java.util.Set<T>), E, m(java.util.Set<T>), D
+5 errors