Fix #5029 - infinite recursion in TypeOps::projectUpwards

This commit is contained in:
Clément Fournier
2024-05-22 16:58:41 +02:00
parent 762181d715
commit 5b24bbea87
2 changed files with 30 additions and 8 deletions

View File

@ -1091,14 +1091,10 @@ public final class TypeOps {
<T extends JTypeMirror> JTypeMirror recurseIfNotDone(T t, BiFunction<T, RecursionStop, JTypeMirror> body) {
if (t instanceof JTypeVar) {
JTypeVar var = (JTypeVar) t;
try {
if (isAbsent(var)) {
return body.apply(t, this);
} else {
return t;
}
} finally {
set.remove(var);
if (isAbsent(var)) {
return body.apply(t, this);
} else {
return t;
}
} else {
return body.apply(t, this);

View File

@ -69,6 +69,32 @@ class TypeOpsTest : FunSpec({
output = listOf(`t_List{String}`, `t_List{Integer}`))
}
test("Bug #5029: Recursive type projection") {
val (acu, spy) = javaParser.parseWithTypeInferenceSpy(
"""
class Job<J extends Job<J, R>, R extends Run<J, R>> {
J getLast() { return null; }
}
class Run<J extends Job<J, R>, R extends Run<J, R>> {}
class Foo {
static Job<?, ?> foo(Job<?,?> job) {
var x = job.getLast();
return x;
}
}
""".trimIndent()
)
val (jobt, runt) = acu.declaredTypeSignatures()
val xVar = acu.varId("x")
spy.shouldBeOk {
xVar shouldHaveType jobt[`?` extends jobt[`?`, `?` extends runt[`?`, `?`]], `?`]
}
}
}
}