Skip to content

Commit c552416

Browse files
committed
Fix IDE crash on @afterclass
The TreeAccumulator was stuck in an infinite loop over the synthetic constructor of java annotations. This could be reproduced by opening the CompilationTests.scala in the IDE.
1 parent 2516575 commit c552416

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

compiler/src/dotty/tools/dotc/interactive/InteractiveDriver.scala

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,14 +182,24 @@ class InteractiveDriver(settings: List[String]) extends Driver {
182182
* of a previous run. Note that typed trees can have untyped or partially
183183
* typed children if the source contains errors.
184184
*/
185-
private def cleanup(tree: tpd.Tree)(implicit ctx: Context): Unit = tree.foreachSubTree { t =>
186-
if (t.hasType) {
187-
if (t.symbol.exists) {
188-
if (!t.symbol.isCompleted) t.symbol.info = UnspecifiedErrorType
189-
t.symbol.annotations.foreach(annot => cleanup(annot.tree))
185+
private def cleanup(tree: tpd.Tree)(implicit ctx: Context): Unit = {
186+
val cleanedTree = mutable.Set.empty[tpd.Tree]
187+
def cleanupTree(tree: tpd.Tree): Unit = {
188+
cleanedTree += tree
189+
tree.foreachSubTree { t =>
190+
if (t.hasType) {
191+
if (t.symbol.exists) {
192+
if (!t.symbol.isCompleted) t.symbol.info = UnspecifiedErrorType
193+
t.symbol.annotations.foreach { annot =>
194+
if (!cleanedTree(annot.tree))
195+
cleanupTree(annot.tree)
196+
}
197+
}
198+
}
199+
t.removeAllAttachments()
190200
}
191201
}
192-
t.removeAllAttachments()
202+
cleanupTree(tree)
193203
}
194204

195205
def run(uri: URI, sourceCode: String): List[MessageContainer] = {

0 commit comments

Comments
 (0)