Skip to content

Commit 3cc73e6

Browse files
Compilation error with Eclipse 4.39 not with javac or Eclipse 4.38
Improve the impl to cover one more issue + really make ivar-ivar dependencies bidirectional + also consider ivar-super bounds in ivar prioritization - but not so for same bounds Also fix an NPE in debug logging Fixes #4937
1 parent 9ee5bfa commit 3cc73e6

2 files changed

Lines changed: 33 additions & 7 deletions

File tree

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -430,10 +430,16 @@ else if (boundNullBits != 0) // combine bits from both sources, even if this cre
430430
// for a dependency between two IVs make a note about the inverse bound.
431431
// this should be needed to determine IV dependencies independent of direction.
432432
// TODO: so far no test could be identified which actually needs it ...
433-
InferenceVariable rightIV = (InferenceVariable) bound.right.prototype();
434-
three = this.boundsPerVariable.get(rightIV);
435-
if (three == null)
436-
this.boundsPerVariable.put(rightIV, (three = new ThreeSets()));
433+
int relation = switch (bound.relation) {
434+
case ReductionResult.SUBTYPE -> ReductionResult.SUPERTYPE;
435+
case ReductionResult.SUPERTYPE -> ReductionResult.SUBTYPE;
436+
default -> -1;
437+
};
438+
if (relation != -1) {
439+
InferenceVariable rightIV = (InferenceVariable) bound.right.prototype();
440+
three = this.boundsPerVariable.computeIfAbsent(rightIV, k -> new ThreeSets());
441+
three.addBound(new TypeBound(rightIV, bound.left, relation));
442+
}
437443
}
438444
}
439445
}
@@ -722,7 +728,8 @@ protected TypeBinding getP(int i) {
722728
if (InferenceContext18.DEBUG) {
723729
if (!capturesToRemove.isEmpty()) {
724730
for (ParameterizedTypeBinding toRemove : capturesToRemove) {
725-
System.out.println("Removing capture bound " + //$NON-NLS-1$
731+
if (this.captures.containsKey(toRemove))
732+
System.out.println("Removing capture bound " + //$NON-NLS-1$
726733
String.valueOf(toRemove.shortReadableName()) +
727734
"=capture("+String.valueOf(this.captures.get(toRemove).shortReadableName())+")"); //$NON-NLS-1$ //$NON-NLS-2$
728735
}
@@ -1073,8 +1080,7 @@ public int rankIVar(InferenceVariable ivar) {
10731080
if (!(bound.right instanceof InferenceVariable))
10741081
return 1;
10751082
if (three.superBounds != null)
1076-
for (TypeBound bound :three.superBounds)
1077-
if (!(bound.right instanceof InferenceVariable))
1083+
if (!three.superBounds.isEmpty())
10781084
return 2;
10791085
}
10801086
return 3;

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

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

2077+
public void testGH4937() {
2078+
runConformTest(new String[] {
2079+
"A.java",
2080+
"""
2081+
import java.util.List;
2082+
2083+
public class A {
2084+
public static void foo() {
2085+
System.out.println(List.of(BusinessExtractBuilder.create())); // Error here
2086+
}
2087+
public static class BusinessExtractBuilder<T> {
2088+
public static <U extends BusinessExtractBuilder<U>> U create() {
2089+
return null;
2090+
}
2091+
}
2092+
}
2093+
"""
2094+
});
2095+
}
2096+
20772097
public static Class<GenericsRegressionTest_9> testClass() {
20782098
return GenericsRegressionTest_9.class;
20792099
}

0 commit comments

Comments
 (0)