Skip to content

Commit 164802b

Browse files
ECJ doesn't compile on Collections.unmodifiableSet(Set<? super Integer>) but javac does (eclipse-jdt#4104)
+ remove bogus uncapture from eclipse-jdt#3915 as suggested by coehlrich + fix variant test case by more capturing of PTB super types Fixes eclipse-jdt#4098
1 parent 17d59b6 commit 164802b

4 files changed

Lines changed: 45 additions & 10 deletions

File tree

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2219,12 +2219,4 @@ public static TypeBinding maybeCapture(TypeBinding type) {
22192219
}
22202220
return type;
22212221
}
2222-
2223-
public static TypeBinding maybeUncapture(CaptureBinding capture) {
2224-
InferenceContext18 inst = instance.get();
2225-
if (inst != null) {
2226-
return capture.uncapture(inst.scope);
2227-
}
2228-
return capture;
2229-
}
22302222
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,6 +1514,7 @@ public ReferenceBinding superclass() {
15141514
ReferenceBinding genericSuperclass = this.type.superclass();
15151515
if (genericSuperclass == null) return null; // e.g. interfaces
15161516
this.superclass = (ReferenceBinding) Scope.substitute(this, genericSuperclass);
1517+
this.superclass = (ReferenceBinding) InferenceContext18.maybeCapture(this.superclass);
15171518
this.typeBits |= (this.superclass.typeBits & TypeIds.InheritableBits);
15181519
if ((this.typeBits & (TypeIds.BitAutoCloseable|TypeIds.BitCloseable)) != 0) // avoid the side-effects of hasTypeBit()!
15191520
this.typeBits |= applyCloseableWhitelists(this.environment.globalOptions);
@@ -1532,6 +1533,7 @@ public ReferenceBinding[] superInterfaces() {
15321533
this.superInterfaces = Scope.substitute(this, this.type.superInterfaces());
15331534
if (this.superInterfaces != null) {
15341535
for (int i = this.superInterfaces.length; --i >= 0;) {
1536+
this.superInterfaces[i] = (ReferenceBinding) InferenceContext18.maybeCapture(this.superInterfaces[i]);
15351537
this.typeBits |= (this.superInterfaces[i].typeBits & TypeIds.InheritableBits);
15361538
if ((this.typeBits & (TypeIds.BitAutoCloseable|TypeIds.BitCloseable)) != 0) // avoid the side-effects of hasTypeBit()!
15371539
this.typeBits |= applyCloseableWhitelists(this.environment.globalOptions);

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1390,8 +1390,6 @@ public boolean isTypeArgumentContainedBy(TypeBinding otherType) {
13901390
for (TypeBinding intersectingType : intersectingTypes)
13911391
if (TypeBinding.equalsEquals(intersectingType, this))
13921392
return true;
1393-
} else if (otherBound instanceof CaptureBinding capture) {
1394-
otherBound = InferenceContext18.maybeUncapture(capture); // not backed by JLS
13951393
}
13961394
if (TypeBinding.equalsEquals(otherBound, this))
13971395
return true; // ? extends T <= ? extends ? extends T

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,6 +1096,30 @@ public static <T> IQuery<T> createCompoundQuery(Collection<? extends IQuery<? ex
10961096
"""
10971097
});
10981098
}
1099+
public void testGH3457c() {
1100+
runConformTest(new String[] {
1101+
"QueryUtil.java",
1102+
"""
1103+
import java.util.ArrayList;
1104+
import java.util.Collection;
1105+
import java.util.List;
1106+
1107+
interface IQuery<T> extends List<T> { }
1108+
1109+
public class QueryUtil {
1110+
public static <T> IQuery<T> createCompoundQuery(IQuery<? extends T> query1, IQuery<T> query2, boolean and) {
1111+
ArrayList<IQuery<? extends T>> queries = new ArrayList<>(2);
1112+
queries.add(query1);
1113+
queries.add(query2);
1114+
return createCompoundQuery(queries, and);
1115+
}
1116+
public static <T> IQuery<T> createCompoundQuery(Collection<? extends List<? extends T>> queries, boolean and) {
1117+
return null;
1118+
}
1119+
}
1120+
"""
1121+
});
1122+
}
10991123
public void testGH3948() {
11001124
runConformTest(new String[] {
11011125
"Foo.java",
@@ -1292,6 +1316,25 @@ public static void main(String[] args) {
12921316
"""
12931317
});
12941318
}
1319+
1320+
public void testGH4098() {
1321+
runConformTest(new String[] {
1322+
"ClassA.java",
1323+
"""
1324+
import java.util.Collections;
1325+
import java.util.HashSet;
1326+
import java.util.Set;
1327+
1328+
public class ClassA {
1329+
public static void main(String[] args) {
1330+
Set<? super Integer> set = new HashSet<>(Set.of(1, 5));
1331+
System.out.println(Collections.unmodifiableSet(set));
1332+
}
1333+
}
1334+
"""
1335+
});
1336+
}
1337+
12951338
public static Class<GenericsRegressionTest_9> testClass() {
12961339
return GenericsRegressionTest_9.class;
12971340
}

0 commit comments

Comments
 (0)