From 5f7ef0cd566b1e1100f910cd2004c549821b5039 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 14 Aug 2017 10:19:19 +0200 Subject: [PATCH 1/4] Survive empty base classes in overriddenFromType --- compiler/src/dotty/tools/dotc/core/SymDenotations.scala | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala index bfaa12729090..15c943b29640 100644 --- a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala @@ -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`. * From d474afac2d692ce53ce9804bbf4835a27c2354de Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 16 Aug 2017 10:51:21 +0200 Subject: [PATCH 2/4] Clean up trees after type checking in IDE --- .../dotty/tools/dotc/interactive/InteractiveDriver.scala | 9 +++++++++ compiler/src/dotty/tools/dotc/util/Attachment.scala | 3 +++ 2 files changed, 12 insertions(+) diff --git a/compiler/src/dotty/tools/dotc/interactive/InteractiveDriver.scala b/compiler/src/dotty/tools/dotc/interactive/InteractiveDriver.scala index 8bfc6fef3eb3..6c2d98c801fb 100644 --- a/compiler/src/dotty/tools/dotc/interactive/InteractiveDriver.scala +++ b/compiler/src/dotty/tools/dotc/interactive/InteractiveDriver.scala @@ -179,6 +179,14 @@ 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 => + if (t.hasType) { + if (t.symbol.exists && !t.symbol.isCompleted) + t.symbol.info = UnspecifiedErrorType + } + t.removeAllAttachments() + } + def run(uri: URI, sourceCode: String): List[MessageContainer] = { val previousCtx = myCtx try { @@ -200,6 +208,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 diff --git a/compiler/src/dotty/tools/dotc/util/Attachment.scala b/compiler/src/dotty/tools/dotc/util/Attachment.scala index 20facfd97544..ed71aba1c90b 100644 --- a/compiler/src/dotty/tools/dotc/util/Attachment.scala +++ b/compiler/src/dotty/tools/dotc/util/Attachment.scala @@ -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 } } From a3403234253140abc67a6fc30795e7cfe329854c Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 16 Aug 2017 11:05:38 +0200 Subject: [PATCH 3/4] Also clean annotation trees Note: this might involve forcing annotations. --- .../dotty/tools/dotc/interactive/InteractiveDriver.scala | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/interactive/InteractiveDriver.scala b/compiler/src/dotty/tools/dotc/interactive/InteractiveDriver.scala index 6c2d98c801fb..025b1a10d6ee 100644 --- a/compiler/src/dotty/tools/dotc/interactive/InteractiveDriver.scala +++ b/compiler/src/dotty/tools/dotc/interactive/InteractiveDriver.scala @@ -181,8 +181,10 @@ class InteractiveDriver(settings: List[String]) extends Driver { private def cleanup(tree: tpd.Tree)(implicit ctx: Context): Unit = tree.foreachSubTree { t => if (t.hasType) { - if (t.symbol.exists && !t.symbol.isCompleted) - t.symbol.info = UnspecifiedErrorType + if (t.symbol.exists) { + if (!t.symbol.isCompleted) t.symbol.info = UnspecifiedErrorType + t.symbol.annotations.foreach(annot => cleanup(annot.tree)) + } } t.removeAllAttachments() } From 980fcbe4ee9cb00ac4c16b9a047cc5dea5f43abb Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 16 Aug 2017 14:22:41 +0200 Subject: [PATCH 4/4] Add comment --- .../src/dotty/tools/dotc/interactive/InteractiveDriver.scala | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/compiler/src/dotty/tools/dotc/interactive/InteractiveDriver.scala b/compiler/src/dotty/tools/dotc/interactive/InteractiveDriver.scala index 025b1a10d6ee..a27db1d5d5db 100644 --- a/compiler/src/dotty/tools/dotc/interactive/InteractiveDriver.scala +++ b/compiler/src/dotty/tools/dotc/interactive/InteractiveDriver.scala @@ -179,6 +179,11 @@ class InteractiveDriver(settings: List[String]) extends Driver { private val compiler: Compiler = new InteractiveCompiler + /** Remove attachments and error out completers. The goal is to avoid + * having a completer hanging in a typed tree which can capture the context + * 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) {