Skip to content

Commit 079cb7d

Browse files
ECJ Compile Error: "The method sort(List<T>) in the type Collections is not applicable for the arguments ..." (eclipse-jdt#4040)
For now reduce the effect of eclipse-jdt#4023 Fixes eclipse-jdt#4039
1 parent 5302657 commit 079cb7d

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ParameterizedTypeBinding.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,15 @@ public boolean canBeInstantiated() {
169169
}
170170
@Override
171171
public TypeBinding findSuperTypeOriginatingFrom(TypeBinding otherType) {
172+
// see https://github.com/eclipse-jdt/eclipse.jdt.core/issues/4039 :
173+
// if capture makes this and otherType equal, then treat that as the sought super type (for now)
174+
TypeBinding capture = InferenceContext18.maybeCapture(this);
175+
if (TypeBinding.equalsEquals(capture, otherType))
176+
return capture;
177+
172178
if (otherType instanceof ReferenceBinding otherRef && TypeBinding.equalsEquals(this.type, otherRef.actualType()))
173179
return this;
174180

175-
TypeBinding capture = InferenceContext18.maybeCapture(this);
176181
if (capture != this) //$IDENTITY-COMPARISON$
177182
return capture.findSuperTypeOriginatingFrom(otherType);
178183
return super.findSuperTypeOriginatingFrom(otherType);

org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_1_8.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6986,7 +6986,7 @@ public void testBug472851() {
69866986
"1. ERROR in Test.java (at line 10)\n" +
69876987
" test(type);\n" +
69886988
" ^^^^\n" +
6989-
"The method test(List<L>) in the type Test is not applicable for the arguments (List<capture#1-of ? extends List<?>>)\n" +
6989+
"The method test(List<L>) in the type Test is not applicable for the arguments (List<capture#2-of ? extends List<?>>)\n" +
69906990
"----------\n");
69916991
}
69926992
public void testBug502350() {

org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_9.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,6 +1211,30 @@ public static void main(String[] args) {
12111211
"""
12121212
});
12131213
}
1214+
public void testGH4039() {
1215+
runConformTest(new String[] {
1216+
"CollectionsSortReproducer.java",
1217+
"""
1218+
import java.util.Collection;
1219+
import java.util.Collections;
1220+
import java.util.Iterator;
1221+
import java.util.List;
1222+
1223+
public class CollectionsSortReproducer {
1224+
class Cranberry<T_Value> implements Comparable<Cranberry<T_Value>> {
1225+
@Override
1226+
public int compareTo(Cranberry<T_Value> o) { return 0; }
1227+
}
1228+
1229+
public static void main(String[] args) {
1230+
List<Cranberry<?>> l = Collections.emptyList();
1231+
Collections.sort(l);
1232+
}
1233+
}
1234+
"""
1235+
});
1236+
}
1237+
12141238
public static Class<GenericsRegressionTest_9> testClass() {
12151239
return GenericsRegressionTest_9.class;
12161240
}

0 commit comments

Comments
 (0)