Skip to content

Harden IDE: Cleanup trees after typechecking them in IDE #2986

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 4 commits into from
Aug 16, 2017
Merged
Show file tree
Hide file tree
Changes from 3 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
5 changes: 4 additions & 1 deletion compiler/src/dotty/tools/dotc/core/SymDenotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1056,7 +1056,10 @@ object SymDenotations {
else overriddenFromType(owner.asClass.classInfo.selfType)

private def overriddenFromType(tp: Type)(implicit ctx: Context): Iterator[Symbol] =
tp.baseClasses.tail.iterator map overriddenSymbol filter (_.exists)
tp.baseClasses match {
case _ :: inherited => inherited.iterator map overriddenSymbol filter (_.exists)
case Nil => Iterator.empty
}

/** The symbol overriding this symbol in given subclass `ofclazz`.
*
Expand Down
11 changes: 11 additions & 0 deletions compiler/src/dotty/tools/dotc/interactive/InteractiveDriver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,16 @@ class InteractiveDriver(settings: List[String]) extends Driver {

private val compiler: Compiler = new InteractiveCompiler

private def cleanup(tree: tpd.Tree)(implicit ctx: Context): Unit = tree.foreachSubTree { t =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a documentation comment explaining why cleanup is necessary?

if (t.hasType) {
if (t.symbol.exists) {
if (!t.symbol.isCompleted) t.symbol.info = UnspecifiedErrorType
t.symbol.annotations.foreach(annot => cleanup(annot.tree))
}
}
t.removeAllAttachments()
}

def run(uri: URI, sourceCode: String): List[MessageContainer] = {
val previousCtx = myCtx
try {
Expand All @@ -200,6 +210,7 @@ class InteractiveDriver(settings: List[String]) extends Driver {
run.compileSources(List(source))
run.printSummary()
val t = run.units.head.tpdTree
cleanup(t)
myOpenedTrees(uri) = topLevelClassTrees(t, source)

reporter.removeBufferedMessages
Expand Down
3 changes: 3 additions & 0 deletions compiler/src/dotty/tools/dotc/util/Attachment.scala
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,8 @@ object Attachment {
assert(!getAttachment(key).isDefined, s"duplicate attachment for key $key")
next = new Link(key, value, next)
}

final def removeAllAttachments() =
next = null
}
}