Skip to content

Commit fbaf0aa

Browse files
Test case for issue 3351
1 parent 4622511 commit fbaf0aa

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2315,6 +2315,43 @@ public static <U extends BusinessExtractBuilder<U>> U create() {
23152315
});
23162316
}
23172317

2318+
public void testGH3351() {
2319+
// error message is bogus (see https://github.com/eclipse-jdt/eclipse.jdt.core/issues/5078)
2320+
// but rejecting is in line with javac
2321+
runNegativeTest(new String[] {
2322+
"PassThroughGenerics.java",
2323+
"""
2324+
import java.util.List;
2325+
public class PassThroughGenerics {
2326+
private class MyComp implements Comparable<MyComp> {
2327+
@Override public int compareTo(MyComp other) { return 0; }
2328+
}
2329+
2330+
static <E extends Comparable<E>> List<E> sort(List<E> list) {
2331+
return list;
2332+
}
2333+
2334+
static <T> List<T> genericList() {
2335+
return null;
2336+
}
2337+
2338+
public static void main(String[] args) {
2339+
List<MyComp> sorted = sort(genericList());
2340+
System.out.println(sorted);
2341+
}
2342+
}
2343+
"""
2344+
},
2345+
"""
2346+
----------
2347+
1. ERROR in PassThroughGenerics.java (at line 16)
2348+
List<MyComp> sorted = sort(genericList());
2349+
^^^^
2350+
The method sort(java.util.List<E extends java.lang.Comparable<E>>) in the type PassThroughGenerics is not applicable for the arguments (java.util.List<E extends java.lang.Comparable<E>>)
2351+
----------
2352+
""");
2353+
}
2354+
23182355
public static Class<GenericsRegressionTest_9> testClass() {
23192356
return GenericsRegressionTest_9.class;
23202357
}

0 commit comments

Comments
 (0)