From 130d7716e9284a4d87905a0b12b9c2fd9baf8f55 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 8 Jan 2018 17:32:11 +0100 Subject: [PATCH] Fix compiling quote in file with no splices --- .../src/dotty/tools/dotc/CompilationUnit.scala | 15 ++++++++++++--- .../dotty/tools/dotc/transform/PostTyper.scala | 1 + tests/pos/quote-no-splices.scala | 9 +++++++++ 3 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 tests/pos/quote-no-splices.scala diff --git a/compiler/src/dotty/tools/dotc/CompilationUnit.scala b/compiler/src/dotty/tools/dotc/CompilationUnit.scala index c3d9326f180c..c7c5156a83d1 100644 --- a/compiler/src/dotty/tools/dotc/CompilationUnit.scala +++ b/compiler/src/dotty/tools/dotc/CompilationUnit.scala @@ -8,6 +8,7 @@ import dotty.tools.dotc.ast.tpd.{ Tree, TreeTraverser } import dotty.tools.dotc.core.Contexts.Context import dotty.tools.dotc.core.SymDenotations.ClassDenotation import dotty.tools.dotc.core.Symbols._ +import dotty.tools.dotc.transform.SymUtils._ class CompilationUnit(val source: SourceFile) { @@ -35,13 +36,21 @@ object CompilationUnit { assert(!unpickled.isEmpty, unpickled) val unit1 = new CompilationUnit(new SourceFile(clsd.symbol.associatedFile, Seq())) unit1.tpdTree = unpickled - if (forceTrees) + if (forceTrees) { + val force = new Force force.traverse(unit1.tpdTree) + unit1.containsQuotesOrSplices = force.containsQuotes + } unit1 } /** Force the tree to be loaded */ - private object force extends TreeTraverser { - def traverse(tree: Tree)(implicit ctx: Context): Unit = traverseChildren(tree) + private class Force extends TreeTraverser { + var containsQuotes = false + def traverse(tree: Tree)(implicit ctx: Context): Unit = { + if (tree.symbol.isQuote) + containsQuotes = true + traverseChildren(tree) + } } } diff --git a/compiler/src/dotty/tools/dotc/transform/PostTyper.scala b/compiler/src/dotty/tools/dotc/transform/PostTyper.scala index 46fb723e2391..3807a25b09c2 100644 --- a/compiler/src/dotty/tools/dotc/transform/PostTyper.scala +++ b/compiler/src/dotty/tools/dotc/transform/PostTyper.scala @@ -180,6 +180,7 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase override def transform(tree: Tree)(implicit ctx: Context): Tree = try tree match { case tree: Ident if !tree.isType => + handleMeta(tree.symbol) tree.tpe match { case tpe: ThisType => This(tpe.cls).withPos(tree.pos) case _ => tree diff --git a/tests/pos/quote-no-splices.scala b/tests/pos/quote-no-splices.scala new file mode 100644 index 000000000000..7f67c60492ce --- /dev/null +++ b/tests/pos/quote-no-splices.scala @@ -0,0 +1,9 @@ +class Foo { + def foo: Unit = { + val expr ='{ + val a = 3 + println("foo") + 2 + a + } + } +}