Thu, 06 Jun 2013 15:33:40 +0100
8008627: Compiler mishandles three-way return-type-substitutability
Summary: Compiler should not enforce an order in how ambiguous methods should be resolved
Reviewed-by: jjg, vromero
1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Check.java Thu Jun 06 15:32:41 2013 +0100 1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Check.java Thu Jun 06 15:33:40 2013 +0100 1.3 @@ -1924,24 +1924,11 @@ 1.4 Symbol s3 = e.sym; 1.5 if (s3 == s1 || s3 == s2 || s3.kind != MTH || (s3.flags() & (BRIDGE|SYNTHETIC)) != 0) continue; 1.6 Type st3 = types.memberType(site,s3); 1.7 - if (types.overrideEquivalent(st3, st1) && types.overrideEquivalent(st3, st2)) { 1.8 - if (s3.owner == site.tsym) { 1.9 - return true; 1.10 - } 1.11 - List<Type> tvars1 = st1.getTypeArguments(); 1.12 - List<Type> tvars2 = st2.getTypeArguments(); 1.13 - List<Type> tvars3 = st3.getTypeArguments(); 1.14 - Type rt1 = st1.getReturnType(); 1.15 - Type rt2 = st2.getReturnType(); 1.16 - Type rt13 = types.subst(st3.getReturnType(), tvars3, tvars1); 1.17 - Type rt23 = types.subst(st3.getReturnType(), tvars3, tvars2); 1.18 - boolean compat = 1.19 - !rt13.isPrimitiveOrVoid() && 1.20 - !rt23.isPrimitiveOrVoid() && 1.21 - (types.covariantReturnType(rt13, rt1, types.noWarnings) && 1.22 - types.covariantReturnType(rt23, rt2, types.noWarnings)); 1.23 - if (compat) 1.24 - return true; 1.25 + if (types.overrideEquivalent(st3, st1) && 1.26 + types.overrideEquivalent(st3, st2) && 1.27 + types.returnTypeSubstitutable(st3, st1) && 1.28 + types.returnTypeSubstitutable(st3, st2)) { 1.29 + return true; 1.30 } 1.31 } 1.32 }
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/test/tools/javac/generics/rawOverride/T8008627.java Thu Jun 06 15:33:40 2013 +0100 2.3 @@ -0,0 +1,47 @@ 2.4 +/* 2.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.7 + * 2.8 + * This code is free software; you can redistribute it and/or modify it 2.9 + * under the terms of the GNU General Public License version 2 only, as 2.10 + * published by the Free Software Foundation. 2.11 + * 2.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 2.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 2.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 2.15 + * version 2 for more details (a copy is included in the LICENSE file that 2.16 + * accompanied this code). 2.17 + * 2.18 + * You should have received a copy of the GNU General Public License version 2.19 + * 2 along with this work; if not, write to the Free Software Foundation, 2.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2.21 + * 2.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2.23 + * or visit www.oracle.com if you need additional information or have any 2.24 + * questions. 2.25 + */ 2.26 + 2.27 +/* 2.28 + * @test 2.29 + * @bug 8008627 2.30 + * @summary Compiler mishandles three-way return-type-substitutability 2.31 + * @compile T8008627.java 2.32 + */ 2.33 + 2.34 +class T8008627 { 2.35 + 2.36 + interface I { 2.37 + Object m(Iterable l); 2.38 + } 2.39 + 2.40 + interface J<S> { 2.41 + S m(Iterable<String> l); 2.42 + } 2.43 + 2.44 + interface K<T> { 2.45 + T m(Iterable<String> l); 2.46 + } 2.47 + 2.48 + @FunctionalInterface 2.49 + interface Functional<S,T> extends I, J<S>, K<T> {} 2.50 +}
3.1 --- a/test/tools/javac/lambda/funcInterfaces/NonSAM2.java Thu Jun 06 15:32:41 2013 +0100 3.2 +++ b/test/tools/javac/lambda/funcInterfaces/NonSAM2.java Thu Jun 06 15:33:40 2013 +0100 3.3 @@ -13,7 +13,7 @@ 3.4 interface Foo1Bar1 extends Foo1, Bar1 {} //types Bar1 and Foo1 are incompatible; both define getAge(String), but with unrelated return types 3.5 3.6 interface AC extends A, C {} //name clash: getOldest(List<?>) in C and getOldest(List<Number>) in A have the same erasure, yet neither overrides the other 3.7 -interface ABC extends A, B, C {} //name clash: getOldest(List<?>) in C and getOldest(List<Number>) in A have the same erasure, yet neither overrides the other 3.8 +interface ABC extends A, B, C {} //ok - raw override 3.9 interface AD extends A, D {} //name clash: getOldest(List<Integer>) in D and getOldest(List<Number>) in A have the same erasure, yet neither overrides the other 3.10 3.11 interface Foo2<T> { void m(T arg);}
4.1 --- a/test/tools/javac/lambda/funcInterfaces/NonSAM2.out Thu Jun 06 15:32:41 2013 +0100 4.2 +++ b/test/tools/javac/lambda/funcInterfaces/NonSAM2.out Thu Jun 06 15:33:40 2013 +0100 4.3 @@ -1,6 +1,5 @@ 4.4 NonSAM2.java:13:1: compiler.err.types.incompatible.diff.ret: Bar1, Foo1, getAge(java.lang.String) 4.5 NonSAM2.java:15:1: compiler.err.name.clash.same.erasure.no.override: getOldest(java.util.List<?>), C, getOldest(java.util.List<java.lang.Number>), A 4.6 -NonSAM2.java:16:1: compiler.err.name.clash.same.erasure.no.override: getOldest(java.util.List<?>), C, getOldest(java.util.List<java.lang.Number>), A 4.7 NonSAM2.java:17:1: compiler.err.name.clash.same.erasure.no.override: getOldest(java.util.List<java.lang.Integer>), D, getOldest(java.util.List<java.lang.Number>), A 4.8 NonSAM2.java:21:1: compiler.err.name.clash.same.erasure.no.override: m(S), Bar2, m(T), Foo2 4.9 -5 errors 4.10 +4 errors