Skip to content

Fix compiling quote in file with no splices #3777

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions compiler/src/dotty/tools/dotc/CompilationUnit.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down Expand Up @@ -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)
}
}
}
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/transform/PostTyper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions tests/pos/quote-no-splices.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Foo {
def foo: Unit = {
val expr ='{
val a = 3
println("foo")
2 + a
}
}
}