mirror of
https://github.com/openjdk/jdk.git
synced 2026-01-28 12:09:14 +00:00
8320220: Compilation of cyclic hierarchy causes infinite recursion
Reviewed-by: vromero, jlahoda
This commit is contained in:
parent
a3188e0406
commit
b78043fdc6
@ -2374,7 +2374,12 @@ public class Check {
|
||||
return;
|
||||
if (seenClasses.contains(c)) {
|
||||
errorFound = true;
|
||||
noteCyclic(pos, (ClassSymbol)c);
|
||||
log.error(pos, Errors.CyclicInheritance(c));
|
||||
seenClasses.stream()
|
||||
.filter(s -> !s.type.isErroneous())
|
||||
.filter(ClassSymbol.class::isInstance)
|
||||
.map(ClassSymbol.class::cast)
|
||||
.forEach(Check.this::handleCyclic);
|
||||
} else if (!c.type.isErroneous()) {
|
||||
try {
|
||||
seenClasses.add(c);
|
||||
@ -2451,7 +2456,8 @@ public class Check {
|
||||
if ((c.flags_field & ACYCLIC) != 0) return true;
|
||||
|
||||
if ((c.flags_field & LOCKED) != 0) {
|
||||
noteCyclic(pos, (ClassSymbol)c);
|
||||
log.error(pos, Errors.CyclicInheritance(c));
|
||||
handleCyclic((ClassSymbol)c);
|
||||
} else if (!c.type.isErroneous()) {
|
||||
try {
|
||||
c.flags_field |= LOCKED;
|
||||
@ -2478,9 +2484,10 @@ public class Check {
|
||||
return complete;
|
||||
}
|
||||
|
||||
/** Note that we found an inheritance cycle. */
|
||||
private void noteCyclic(DiagnosticPosition pos, ClassSymbol c) {
|
||||
log.error(pos, Errors.CyclicInheritance(c));
|
||||
/** Handle finding an inheritance cycle on a class by setting
|
||||
* the class' and its supertypes' types to the error type.
|
||||
**/
|
||||
private void handleCyclic(ClassSymbol c) {
|
||||
for (List<Type> l=types.interfaces(c.type); l.nonEmpty(); l=l.tail)
|
||||
l.head = types.createErrorType((ClassSymbol)l.head.tsym, Type.noType);
|
||||
Type st = types.supertype(c.type);
|
||||
|
||||
10
test/langtools/tools/javac/ClassCycle/ClassCycle4.java
Normal file
10
test/langtools/tools/javac/ClassCycle/ClassCycle4.java
Normal file
@ -0,0 +1,10 @@
|
||||
/*
|
||||
* @test /nodynamiccopyright/
|
||||
* @bug 8320220
|
||||
* @summary Fix infinite recursion in cyclic inheritance situation
|
||||
* @compile/fail/ref=ClassCycle4.out -XDrawDiagnostics ClassCycle4.java
|
||||
*/
|
||||
|
||||
interface ClassCycle4 extends I1, I2 {}
|
||||
interface I1 extends ClassCycle4 {}
|
||||
interface I2 extends ClassCycle4 {}
|
||||
2
test/langtools/tools/javac/ClassCycle/ClassCycle4.out
Normal file
2
test/langtools/tools/javac/ClassCycle/ClassCycle4.out
Normal file
@ -0,0 +1,2 @@
|
||||
ClassCycle4.java:8:1: compiler.err.cyclic.inheritance: ClassCycle4
|
||||
1 error
|
||||
Loading…
x
Reference in New Issue
Block a user