Skip to content

Commit 3c91893

Browse files
committed
Fix cycles in classfile parsing
1 parent bd10700 commit 3c91893

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala

+9-5
Original file line numberDiff line numberDiff line change
@@ -619,14 +619,15 @@ class ClassfileParser(
619619
// invariant: `in` and `ctx` should not be captured inside the result function
620620
def parseAttributes(sym: Symbol, pt: Type = WildcardType, isVarargs: Boolean = false)(using ctx: Context, in: DataReader): AttributeCompleter = {
621621
var typeUpdate: Option[Context ?=> Type] = None
622-
622+
var delayedWork: List[Context ?=> Unit] = Nil
623623
val res = new AttributeCompleter {
624624
def complete(tp: Type)(using Context): Type = {
625625
val newType = if (typeUpdate.isEmpty) tp else typeUpdate.get
626626
exceptions.foreach { ex =>
627627
val cls = getClassSymbol(ex.name)
628628
sym.addAnnotation(ThrowsAnnotation(cls.asClass))
629629
}
630+
delayedWork.foreach(_.apply)
630631
cook.apply(newType)
631632
}
632633
}
@@ -680,10 +681,13 @@ class ClassfileParser(
680681

681682
case tpnme.CodeATTR =>
682683
in.skip(attrLen)
683-
if (sym.owner.isAllOf(Flags.JavaInterface)) {
684-
sym.resetFlag(Flags.Deferred)
685-
sym.owner.resetFlag(Flags.PureInterface)
686-
report.log(s"$sym in ${sym.owner} is a java8+ default method.")
684+
// flag test will trigger completion and cycles, thus have to be lazy
685+
delayedWork ::= { (using ctx) =>
686+
if (sym.owner.isAllOf(Flags.JavaInterface)) {
687+
sym.resetFlag(Flags.Deferred)
688+
sym.owner.resetFlag(Flags.PureInterface)
689+
report.log(s"$sym in ${sym.owner} is a java 8+ default method.")
690+
}
687691
}
688692

689693
case _ =>

0 commit comments

Comments
 (0)