Skip to content

Commit bb9d9eb

Browse files
Regression in Eclipse 2025-12: Type mismatch even for variables with the exact same type. (eclipse-jdt#4813)
2 technical fixes + don't cache premature compatibility checks from capture initialization + avoid duplicate intersecting types in IntersectionTypeBinding18 Adjust the test program to avoid using uninitialized local vars Fixes eclipse-jdt#4699
1 parent c344176 commit bb9d9eb

4 files changed

Lines changed: 65 additions & 1 deletion

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ public void initializeBounds(Scope scope, ParameterizedTypeBinding capturedParam
307307
if(scope.environment().usesNullTypeAnnotations()) {
308308
evaluateNullAnnotations(scope, null);
309309
}
310+
this.compatibleCache = null; // any checks during initialization may have produced bogus results, get rid of them now
310311
}
311312

312313
@Override

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,6 +1114,14 @@ public int compare(TypeBinding o1, TypeBinding o2) {
11141114
}
11151115
});
11161116
}
1117+
int j = 0;
1118+
for (int i = 1; i < intersectingTypes.length; i++) {
1119+
if (!TypeBinding.equalsEquals(intersectingTypes[j], intersectingTypes[i])) {
1120+
intersectingTypes[++j] = intersectingTypes[i];
1121+
}
1122+
}
1123+
if (j < intersectingTypes.length)
1124+
intersectingTypes = Arrays.copyOfRange(intersectingTypes, 0, j+1);
11171125
return this.typeSystem.getIntersectionType18(intersectingTypes);
11181126
}
11191127

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ abstract public class ReferenceBinding extends TypeBinding {
9191
char[] constantPoolName;
9292
char[] signature;
9393

94-
private Map<TypeBinding, Boolean> compatibleCache;
94+
protected Map<TypeBinding, Boolean> compatibleCache;
9595

9696
int typeBits; // additional bits characterizing this type
9797
protected MethodBinding [] singleAbstractMethod;

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

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1947,6 +1947,61 @@ public static <T> CompletableFuture<?> future(T t) {
19471947
"""
19481948
});
19491949
}
1950+
public void testGH4699_1() {
1951+
if (this.complianceLevel < ClassFileConstants.JDK10) return; // uses 'var'
1952+
runConformTest(new String[] {
1953+
"EclipseBug.java",
1954+
"""
1955+
public class EclipseBug {
1956+
void error1() {
1957+
var someObject = getObject(); // <<--- Compiler complains here
1958+
}
1959+
private SomeObject<? extends SomeType<?, ? extends SpecialLocation>, ? extends SpecialLocation, ?> getObject() {
1960+
return null;
1961+
}
1962+
static interface SomeLocation { }
1963+
static interface SpecialLocation extends SomeLocation { }
1964+
1965+
static interface SomeType<O extends SomeObject<? extends SomeType<?, L>, L, ? extends SomeObject<?, ?, ?>>, L extends SomeLocation> { }
1966+
1967+
public interface SomeObject<T extends SomeType<?, L>, L extends SomeLocation, P extends SomeObject<?, ?, ?>> { }
1968+
}
1969+
"""
1970+
});
1971+
}
1972+
public void testGH4699_full() {
1973+
if (this.complianceLevel < ClassFileConstants.JDK10) return; // uses 'var'
1974+
runConformTest(new String[] {
1975+
"EclipseBug.java",
1976+
"""
1977+
public class EclipseBug {
1978+
1979+
void error1() {
1980+
var someObject = getObject();
1981+
}
1982+
1983+
void error2(SomeObject<? extends SomeType<?, ? extends SpecialLocation>, ? extends SpecialLocation, ?> theObject) {
1984+
method(theObject);
1985+
}
1986+
1987+
void error3(SomeObject<? extends SomeType<?, ? extends SpecialLocation>, ? extends SpecialLocation, ?> theObject) {
1988+
SomeObject<? extends SomeType<?, ? extends SpecialLocation>, ? extends SpecialLocation, ?> theObject2 = theObject;
1989+
}
1990+
1991+
void method(SomeObject<? extends SomeType<?, ? extends SpecialLocation>, ? extends SpecialLocation, ?> theObject) { }
1992+
1993+
private SomeObject<? extends SomeType<?, ? extends SpecialLocation>, ? extends SpecialLocation, ?> getObject() {
1994+
return null;
1995+
}
1996+
1997+
static interface SomeLocation { }
1998+
static interface SpecialLocation extends SomeLocation { }
1999+
static interface SomeType<O extends SomeObject<? extends SomeType<?, L>, L, ? extends SomeObject<?, ?, ?>>, L extends SomeLocation> { }
2000+
public interface SomeObject<T extends SomeType<?, L>, L extends SomeLocation, P extends SomeObject<?, ?, ?>> { }
2001+
}
2002+
"""
2003+
});
2004+
}
19502005

19512006
public static Class<GenericsRegressionTest_9> testClass() {
19522007
return GenericsRegressionTest_9.class;

0 commit comments

Comments
 (0)