Skip to content

Commit d30e5b8

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

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import util.SourceFile
66
import ast.{tpd, untpd}
77
import dotty.tools.dotc.ast.tpd.{ Tree, TreeTraverser }
88
import dotty.tools.dotc.core.Contexts.Context
9+
import dotty.tools.dotc.core.StdNames._
910
import dotty.tools.dotc.core.SymDenotations.ClassDenotation
1011
import dotty.tools.dotc.core.Symbols._
1112

@@ -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.name.eq(nme.QUOTE) && tree.symbol.owner.eq(defn.OpsPackageClass))
52+
containsQuotes = true
53+
traverseChildren(tree)
54+
}
4655
}
4756
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,9 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
203203
// might be a type constructor.
204204
Checking.checkInstantiable(tree.tpe, nu.pos)
205205
withNoCheckNews(nu :: Nil)(super.transform(tree))
206-
case _ =>
206+
case meth =>
207+
if (meth.symbol.name.eq(nme.QUOTE) && meth.symbol.owner.eq(defn.OpsPackageClass))
208+
ctx.compilationUnit.containsQuotesOrSplices = true
207209
super.transform(tree)
208210
}
209211
case tree: TypeApply =>

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)