Skip to content

Commit 79ce6c0

Browse files
authored
Merge pull request #2986 from dotty-staging/harden-ide-5
Harden IDE: Cleanup trees after typechecking them in IDE
2 parents e9d3f48 + 980fcbe commit 79ce6c0

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

compiler/src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1056,7 +1056,10 @@ object SymDenotations {
10561056
else overriddenFromType(owner.asClass.classInfo.selfType)
10571057

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

10611064
/** The symbol overriding this symbol in given subclass `ofclazz`.
10621065
*

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,21 @@ class InteractiveDriver(settings: List[String]) extends Driver {
179179

180180
private val compiler: Compiler = new InteractiveCompiler
181181

182+
/** Remove attachments and error out completers. The goal is to avoid
183+
* having a completer hanging in a typed tree which can capture the context
184+
* of a previous run. Note that typed trees can have untyped or partially
185+
* typed children if the source contains errors.
186+
*/
187+
private def cleanup(tree: tpd.Tree)(implicit ctx: Context): Unit = tree.foreachSubTree { t =>
188+
if (t.hasType) {
189+
if (t.symbol.exists) {
190+
if (!t.symbol.isCompleted) t.symbol.info = UnspecifiedErrorType
191+
t.symbol.annotations.foreach(annot => cleanup(annot.tree))
192+
}
193+
}
194+
t.removeAllAttachments()
195+
}
196+
182197
def run(uri: URI, sourceCode: String): List[MessageContainer] = {
183198
val previousCtx = myCtx
184199
try {
@@ -200,6 +215,7 @@ class InteractiveDriver(settings: List[String]) extends Driver {
200215
run.compileSources(List(source))
201216
run.printSummary()
202217
val t = run.units.head.tpdTree
218+
cleanup(t)
203219
myOpenedTrees(uri) = topLevelClassTrees(t, source)
204220

205221
reporter.removeBufferedMessages

compiler/src/dotty/tools/dotc/util/Attachment.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,8 @@ object Attachment {
9292
assert(!getAttachment(key).isDefined, s"duplicate attachment for key $key")
9393
next = new Link(key, value, next)
9494
}
95+
96+
final def removeAllAttachments() =
97+
next = null
9598
}
9699
}

0 commit comments

Comments
 (0)