Skip to content

Commit 130d771

Browse files
committed
Fix compiling quote in file with no splices
1 parent aa6459e commit 130d771

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

compiler/src/dotty/tools/dotc/CompilationUnit.scala

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import dotty.tools.dotc.ast.tpd.{ Tree, TreeTraverser }
88
import dotty.tools.dotc.core.Contexts.Context
99
import dotty.tools.dotc.core.SymDenotations.ClassDenotation
1010
import dotty.tools.dotc.core.Symbols._
11+
import dotty.tools.dotc.transform.SymUtils._
1112

1213
class CompilationUnit(val source: SourceFile) {
1314

@@ -35,13 +36,21 @@ object CompilationUnit {
3536
assert(!unpickled.isEmpty, unpickled)
3637
val unit1 = new CompilationUnit(new SourceFile(clsd.symbol.associatedFile, Seq()))
3738
unit1.tpdTree = unpickled
38-
if (forceTrees)
39+
if (forceTrees) {
40+
val force = new Force
3941
force.traverse(unit1.tpdTree)
42+
unit1.containsQuotesOrSplices = force.containsQuotes
43+
}
4044
unit1
4145
}
4246

4347
/** Force the tree to be loaded */
44-
private object force extends TreeTraverser {
45-
def traverse(tree: Tree)(implicit ctx: Context): Unit = traverseChildren(tree)
48+
private class Force extends TreeTraverser {
49+
var containsQuotes = false
50+
def traverse(tree: Tree)(implicit ctx: Context): Unit = {
51+
if (tree.symbol.isQuote)
52+
containsQuotes = true
53+
traverseChildren(tree)
54+
}
4655
}
4756
}

compiler/src/dotty/tools/dotc/transform/PostTyper.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
180180
override def transform(tree: Tree)(implicit ctx: Context): Tree =
181181
try tree match {
182182
case tree: Ident if !tree.isType =>
183+
handleMeta(tree.symbol)
183184
tree.tpe match {
184185
case tpe: ThisType => This(tpe.cls).withPos(tree.pos)
185186
case _ => tree

tests/pos/quote-no-splices.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Foo {
2+
def foo: Unit = {
3+
val expr ='{
4+
val a = 3
5+
println("foo")
6+
2 + a
7+
}
8+
}
9+
}

0 commit comments

Comments
 (0)