Skip to content

Commit 6797789

Browse files
authored
Do not check for unchecked conversion if target is not parameterized (eclipse-jdt#4286)
Reduce risk of the error The type X cannot be resolved. It is indirectly referenced from ... Do so by early exit from TypeBinding.needsUncheckedConversion() before findSuperTypeOriginatingFrom(..) could trigger lookup of more types. If leaf targetType is not parameterized, then the answer is known to be `false`. Fix eclipse-jdt#4231
1 parent 0c310d0 commit 6797789

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1557,7 +1557,7 @@ public boolean needsUncheckedConversion(TypeBinding targetType) {
15571557
if (TypeBinding.equalsEquals(this, targetType))
15581558
return false;
15591559
targetType = targetType.leafComponentType();
1560-
if (!(targetType instanceof ReferenceBinding))
1560+
if (!(targetType instanceof ParameterizedTypeBinding))
15611561
return false;
15621562

15631563
TypeBinding currentType = leafComponentType();

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

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10142,4 +10142,50 @@ void test() {
1014210142
"Void methods cannot return a value\n" +
1014310143
"----------\n");
1014410144
}
10145+
10146+
public void testMissingClass_return() {
10147+
Runner runner = new Runner();
10148+
runner.testFiles = new String[] {
10149+
"p1/I.java",
10150+
"""
10151+
package p1;
10152+
public class I {}
10153+
""",
10154+
"p2/P.java",
10155+
"""
10156+
package p2;
10157+
import p1.I;
10158+
public class P extends I {
10159+
public P(Number n) {}
10160+
}
10161+
"""
10162+
};
10163+
runner.runConformTest();
10164+
10165+
// delete binary file I (i.e. simulate removing it from classpath for subsequent compile)
10166+
Util.delete(new File(OUTPUT_DIR, "p1" + File.separator + "I.class"));
10167+
10168+
runner.shouldFlushOutputDirectory = false;
10169+
runner.testFiles = new String[] {
10170+
"p3/C.java",
10171+
"""
10172+
package p3;
10173+
import p2.P;
10174+
class C {
10175+
public Object test() {
10176+
return new P(1);
10177+
}
10178+
10179+
public Object test2() {
10180+
Object o = new P(1);
10181+
return o;
10182+
}
10183+
10184+
}
10185+
"""
10186+
};
10187+
runner.expectedCompilerLog = "";
10188+
runner.runConformTest();
10189+
}
10190+
1014510191
}

0 commit comments

Comments
 (0)