### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: compiler/org/eclipse/jdt/internal/compiler/ast/Expression.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Expression.java,v retrieving revision 1.132 diff -u -r1.132 Expression.java --- compiler/org/eclipse/jdt/internal/compiler/ast/Expression.java 17 Dec 2010 06:40:12 -0000 1.132 +++ compiler/org/eclipse/jdt/internal/compiler/ast/Expression.java 4 Jan 2011 10:52:42 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2010 IBM Corporation and others. + * Copyright (c) 2000, 2011 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -390,8 +390,11 @@ return false; } else { // pre1.5 semantics - no covariance allowed (even if 1.5 compliant, but 1.4 source) - MethodBinding[] castTypeMethods = getAllInheritedMethods((ReferenceBinding) castType); - MethodBinding[] expressionTypeMethods = getAllInheritedMethods((ReferenceBinding) expressionType); + // look at original methods rather than the parameterized variants at 1.4 to detect + // covariance. Otherwise when confronted with one raw type and one parameterized type, + // we could mistakenly detect covariance and scream foul. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=332744 + MethodBinding[] castTypeMethods = getAllOriginalInheritedMethods((ReferenceBinding) castType); + MethodBinding[] expressionTypeMethods = getAllOriginalInheritedMethods((ReferenceBinding) expressionType); int exprMethodsLength = expressionTypeMethods.length; for (int i = 0, castMethodsLength = castTypeMethods.length; i < castMethodsLength; i++) { for (int j = 0; j < exprMethodsLength; j++) { @@ -739,9 +742,12 @@ codeStream.invokeStringConcatenationStringConstructor(); } -private MethodBinding[] getAllInheritedMethods(ReferenceBinding binding) { +private MethodBinding[] getAllOriginalInheritedMethods(ReferenceBinding binding) { ArrayList collector = new ArrayList(); getAllInheritedMethods0(binding, collector); + for (int i = 0, len = collector.size(); i < len; i++) { + collector.set(i, ((MethodBinding)collector.get(i)).original()); + } return (MethodBinding[]) collector.toArray(new MethodBinding[collector.size()]); } #P org.eclipse.jdt.core.tests.compiler Index: src/org/eclipse/jdt/core/tests/compiler/regression/MethodVerifyTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/MethodVerifyTest.java,v retrieving revision 1.221 diff -u -r1.221 MethodVerifyTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/MethodVerifyTest.java 3 Dec 2010 08:44:25 -0000 1.221 +++ src/org/eclipse/jdt/core/tests/compiler/regression/MethodVerifyTest.java 4 Jan 2011 10:52:46 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2010 IBM Corporation and others. + * Copyright (c) 2000, 2011 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -11875,4 +11875,97 @@ compilerOptions14, null); } +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=332744 (all 1.5+) +public void test332744() { + Map compilerOptions15 = getCompilerOptions(); + compilerOptions15.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, CompilerOptions.VERSION_1_5); + compilerOptions15.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5); + compilerOptions15.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5); + this.runConformTest( + new String[] { + "EList.java", + "import java.util.List;\n" + + "public interface EList extends List {\n" + + "}\n", + "FeatureMap.java", + "public interface FeatureMap extends EList {\n" + + " interface Entry {\n" + + " }\n" + + "}\n", + "InternalEList.java", + "public interface InternalEList extends EList {\n" + + "}\n" + }, + "", + null, + true, + null, + compilerOptions15, + null); + + this.runConformTest( + new String[] { + "Client.java", + "public class Client {\n" + + " Client(FeatureMap fm) {\n" + + " InternalEList e = (InternalEList) fm;\n" + + " }\n" + + "}\n" + }, + "", + null, + false, + null, + compilerOptions15, + null); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=332744 (1.4/1.5 mix) +public void test332744b() { + Map compilerOptions15 = getCompilerOptions(); + compilerOptions15.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, CompilerOptions.VERSION_1_5); + compilerOptions15.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5); + compilerOptions15.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5); + this.runConformTest( + new String[] { + "EList.java", + "import java.util.List;\n" + + "public interface EList extends List {\n" + + "}\n", + "FeatureMap.java", + "public interface FeatureMap extends EList {\n" + + " interface Entry {\n" + + " }\n" + + "}\n", + "InternalEList.java", + "public interface InternalEList extends EList {\n" + + "}\n" + }, + "", + null, + true, + null, + compilerOptions15, + null); + + Map compilerOptions14 = getCompilerOptions(); + compilerOptions14.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_2); + compilerOptions14.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_4); + compilerOptions14.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_3); + compilerOptions14.put(JavaCore.COMPILER_PB_UNNECESSARY_TYPE_CHECK, JavaCore.IGNORE); + this.runConformTest( + new String[] { + "Client.java", + "public class Client {\n" + + " Client(FeatureMap fm) {\n" + + " InternalEList e = (InternalEList) fm;\n" + + " }\n" + + "}\n" + }, + "", + null, + false, + null, + compilerOptions14, + null); +} }