Skip to content

Commit

Permalink
Fix #5119: Get underlying argument for synthetic local values
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasstucki committed Oct 2, 2018
1 parent 0309bbf commit f440826
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 5 deletions.
9 changes: 6 additions & 3 deletions compiler/src/dotty/tools/dotc/ast/tpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -942,11 +942,14 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
}
}

/** Map Inlined nodes and InlineProxy references to underlying arguments */
/** Map Inlined nodes, InlineProxy references and Synthetic val references to underlying arguments */
object mapToUnderlying extends TreeMap {
override def transform(tree: Tree)(implicit ctx: Context): Tree = tree match {
case tree: Ident if tree.symbol.is(InlineProxy) =>
tree.symbol.defTree.asInstanceOf[ValOrDefDef].rhs.underlyingArgument
case tree: Ident if tree.symbol.is(InlineProxy) || (tree.symbol.is(Synthetic) && !tree.symbol.owner.isClass) =>
tree.symbol.defTree match {
case defTree: ValOrDefDef => defTree.rhs.underlyingArgument
case _ => tree
}
case Inlined(_, _, arg) =>
arg.underlyingArgument
case tree =>
Expand Down
1 change: 1 addition & 0 deletions compiler/test/dotc/run-test-pickling.blacklist
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ i4803d
i4803e
i4803f
i4947b
i5119
implicitShortcut
lazy-implicit-lists.scala
lazy-implicit-nums.scala
Expand Down
2 changes: 2 additions & 0 deletions tests/run/i5119.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Term.Select(Term.Apply(Term.Select(Term.New(TypeTree.TypeIdent("StringContextOps")), "<init>", Some(Signature(List(scala.Function0), Macro$.StringContextOps))), List(Term.Apply(Term.Select(Term.Select(Term.Select(Term.Ident("_root_"), "scala", None), "StringContext", None), "apply", Some(Signature(List(scala.collection.Seq), scala.StringContext))), List(Term.Typed(Term.Repeated(List(Term.Literal(Constant.String("Hello World ")), Term.Literal(Constant.String("!")))), TypeTree.Synthetic()))))), "inline$sc", Some(Signature(Nil, scala.StringContext)))
Term.Typed(Term.Repeated(List(Term.Literal(Constant.Int(1)))), TypeTree.Synthetic())
13 changes: 13 additions & 0 deletions tests/run/i5119/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import scala.quoted._
import scala.tasty.Tasty

object Macro {
class StringContextOps(sc: => StringContext) {
inline def ff(args: => Any*): String = ~Macro.impl('(sc), '(args))
}
implicit inline def XmlQuote(sc: => StringContext): StringContextOps = new StringContextOps(sc)
def impl(sc: Expr[StringContext], args: Expr[Seq[Any]])(implicit tasty: Tasty): Expr[String] = {
import tasty._
(sc.toTasty.underlyingArgument.show + "\n" + args.toTasty.underlyingArgument.show).toExpr
}
}
8 changes: 8 additions & 0 deletions tests/run/i5119/Main_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

object Test {
import Macro._

def main(args: Array[String]): Unit = {
println(ff"Hello World ${1}!")
}
}
4 changes: 2 additions & 2 deletions tests/run/xml-interpolation/Test_2.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import XmlQuote._

object Test {
def main(args: Array[String]): Unit = {
// TODO: enable once #5119 is fixed
// assert(xml"Hello Allan!" == Xml("Hello Allan!", Nil))

assert(xml"Hello Allan!" == Xml("Hello Allan!", Nil))

val name = new Object{}
assert(xml"Hello $name!" == Xml("Hello ??!", List(name)))
Expand Down

0 comments on commit f440826

Please sign in to comment.