Skip to content

Fix IDE crash on @AfterClass #3027

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions compiler/src/dotty/tools/dotc/interactive/InteractiveDriver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,28 @@ class InteractiveDriver(settings: List[String]) extends Driver {
* of a previous run. Note that typed trees can have untyped or partially
* typed children if the source contains errors.
*/
private def cleanup(tree: tpd.Tree)(implicit ctx: Context): Unit = tree.foreachSubTree { t =>
if (t.hasType) {
if (t.symbol.exists) {
if (!t.symbol.isCompleted) t.symbol.info = UnspecifiedErrorType
t.symbol.annotations.foreach(annot => cleanup(annot.tree))
private def cleanup(tree: tpd.Tree)(implicit ctx: Context): Unit = {
val seen = mutable.Set.empty[tpd.Tree]
def cleanupTree(tree: tpd.Tree): Unit = {
seen += tree
tree.foreachSubTree { t =>
if (t.symbol.exists && t.hasType) {
if (!t.symbol.isCompleted) t.symbol.info = UnspecifiedErrorType
t.symbol.annotations.foreach { annot =>
/* In some cases annotations are are used on themself (possibly larger cycles).
* This is the case with the java.lang.annotation.Target annotation, would end
* in an infinite loop while cleaning. The `seen` is added to ensure that those
* trees are not cleand twice.
* TODO: Find a less expensive way to check for those cycles.
*/
if (!seen(annot.tree))
cleanupTree(annot.tree)
}
}
t.removeAllAttachments()
}
}
t.removeAllAttachments()
cleanupTree(tree)
}

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