forked from phoedos/pmd
Fix #5029 - infinite recursion in TypeOps::projectUpwards
This commit is contained in:
@ -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);
|
||||
|
@ -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[`?`, `?`]], `?`]
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user