Thu, 23 Oct 2008 18:00:05 +0100
6487370: javac incorrectly gives ambiguity warning with override-equivalent abstract inherited methods
Summary: Javac should not compare erased return types when checking for ambiguity errors during overload resolution
Reviewed-by: jjg
src/share/classes/com/sun/tools/javac/comp/Resolve.java | file | annotate | diff | comparison | revisions | |
test/tools/javac/generics/6487370/T6487370.java | file | annotate | diff | comparison | revisions |
1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Resolve.java Thu Oct 23 17:59:43 2008 +0100 1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Resolve.java Thu Oct 23 18:00:05 2008 +0100 1.3 @@ -650,8 +650,9 @@ 1.4 // both abstract or both concrete 1.5 if (!m1Abstract && !m2Abstract) 1.6 return new AmbiguityError(m1, m2); 1.7 - // check for same erasure 1.8 - if (!types.isSameType(m1.erasure(types), m2.erasure(types))) 1.9 + // check that both signatures have the same erasure 1.10 + if (!types.isSameTypes(m1.erasure(types).getParameterTypes(), 1.11 + m2.erasure(types).getParameterTypes())) 1.12 return new AmbiguityError(m1, m2); 1.13 // both abstract, neither overridden; merge throws clause and result type 1.14 Symbol result;
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/test/tools/javac/generics/6487370/T6487370.java Thu Oct 23 18:00:05 2008 +0100 2.3 @@ -0,0 +1,56 @@ 2.4 +/* 2.5 + * Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 2.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 2.24 + * have any questions. 2.25 + */ 2.26 + 2.27 +/* 2.28 + * @test 2.29 + * @bug 6487370 2.30 + * @author Maurizio Cimadamore 2.31 + * @summary javac incorrectly gives ambiguity warning with override-equivalent abstract inherited methods 2.32 + */ 2.33 + 2.34 +public class T6487370 { 2.35 + 2.36 + interface I1 { 2.37 + String m(Number n); 2.38 + } 2.39 + 2.40 + interface I2 { 2.41 + Object m(Number n); 2.42 + } 2.43 + 2.44 + static abstract class X implements I1, I2 { 2.45 + String test() { 2.46 + return m(0.0f); 2.47 + } 2.48 + } 2.49 + 2.50 + static class W extends X { 2.51 + public String m(Number n) { 2.52 + return "Hello!"; 2.53 + } 2.54 + } 2.55 + 2.56 + public static void main(String args[]) { 2.57 + System.out.println(new W().test()); 2.58 + } 2.59 +}