Skip to content

Commit 10639fb

Browse files
Total IDE freeze during type inference of recursive generic type (#5059)
+ invent new incorporation rule (marked NON-JLS) + change in TypeBound is only for improved debugging support Fixes #5052
1 parent f256de1 commit 10639fb

3 files changed

Lines changed: 45 additions & 5 deletions

File tree

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -867,12 +867,19 @@ private ConstraintTypeFormula combineSuperAndSub(TypeBound boundS, TypeBound bou
867867

868868
private ConstraintTypeFormula combineEqualSupers(TypeBound boundS, TypeBound boundT) {
869869
// more permutations of: S <: α and α <: T imply ⟨S <: T⟩
870+
boolean outerSame = false;
871+
boolean innerSame = false;
870872
if (TypeBinding.equalsEquals(boundS.left, boundT.right))
871-
// came in as: α REL S and T REL α imply ⟨T REL S⟩
872-
return ConstraintTypeFormula.create(boundT.left, boundS.right, boundS.relation, boundT.isSoft||boundS.isSoft);
873+
outerSame = true; // came in as: α REL S and T REL α imply ⟨T REL S⟩
873874
if (TypeBinding.equalsEquals(boundS.right, boundT.left))
874-
// came in as: S REL α and α REL T imply ⟨S REL T⟩
875+
innerSame = true; // came in as: S REL α and α REL T imply ⟨S REL T⟩
876+
if (outerSame) {
877+
if (innerSame) // NON-JLS bidirectional subtyping implies equality:
878+
return ConstraintTypeFormula.create(boundS.left, boundS.right, ReductionResult.SAME, false);
879+
return ConstraintTypeFormula.create(boundT.left, boundS.right, boundS.relation, boundT.isSoft||boundS.isSoft);
880+
} else if (innerSame) {
875881
return ConstraintTypeFormula.create(boundS.left, boundT.right, boundS.relation, boundT.isSoft||boundS.isSoft);
882+
}
876883
return null;
877884
}
878885

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2013, 2018 GK Software AG and others.
2+
* Copyright (c) 2013, 2026 GK Software SE and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -88,7 +88,10 @@ public String toString() {
8888
buf.append(isBound ? "TypeBound " : "Dependency "); //$NON-NLS-1$ //$NON-NLS-2$
8989
buf.append(this.left.sourceName);
9090
buf.append(relationToString(this.relation));
91-
buf.append(this.right.readableName());
91+
if (this.right instanceof CaptureBinding18)
92+
buf.append(this.right.toString());
93+
else
94+
buf.append(this.right.readableName());
9295
return buf.toString();
9396
}
9497
}

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2074,6 +2074,36 @@ TypeConverter<?> findCompatibleConverter(Class<?> clazz) {
20742074
});
20752075
}
20762076

2077+
public void testGH5052() {
2078+
runConformTest(new String[] {
2079+
"Freeze.java",
2080+
"""
2081+
import java.util.function.Function;
2082+
2083+
public class Freeze {
2084+
interface Ifc<S> {}
2085+
class Val implements Ifc<Val> {}
2086+
2087+
public static void main(String... args) {
2088+
Val v = null; // specific value doesn't matter here
2089+
consume(v, t -> someMapper(t));
2090+
}
2091+
2092+
static <T> void consume(T t, Function<T,T> mapper) {
2093+
mapper.apply(null);
2094+
System.out.print("consume");
2095+
// impl doesn't matter here
2096+
}
2097+
2098+
static <U extends Ifc<U>> U someMapper(U u) {
2099+
System.out.print("map.");
2100+
return null; // impl doesn't matter here
2101+
}
2102+
}
2103+
"""
2104+
},
2105+
"map.consume");
2106+
}
20772107
public static Class<GenericsRegressionTest_9> testClass() {
20782108
return GenericsRegressionTest_9.class;
20792109
}

0 commit comments

Comments
 (0)