Skip to content
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

Fix #5119: Get underlying argument for synthetic local values #5189

Merged
merged 4 commits into from
Oct 2, 2018
Merged
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
16 changes: 9 additions & 7 deletions compiler/src/dotty/tools/dotc/ast/tpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -942,15 +942,17 @@ 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 Inlined(_, _, arg) =>
arg.underlyingArgument
case tree =>
super.transform(tree)
case tree: Ident if tree.symbol.is(InlineProxy) || (tree.symbol.is(Synthetic) && !tree.symbol.owner.isClass) =>
tree.symbol.defTree match {
case defTree: ValOrDefDef => transform(defTree.rhs)
case _ => tree
}
case Inlined(_, _, arg) => transform(arg)
case NamedArg(_, arg) => transform(arg)
case tree => super.transform(tree)
}
}

Expand Down
2 changes: 2 additions & 0 deletions compiler/test/dotc/run-test-pickling.blacklist
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ i4803d
i4803e
i4803f
i4947b
i5119
i5119b
inline-varargs-1
implicitShortcut
lazy-implicit-lists.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: 4 additions & 0 deletions tests/run/i5119b.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Term.Apply(Term.Ident("foo"), List(Term.Literal(Constant.Int(1))))
Term.Apply(Term.Ident("foo"), List(Term.Literal(Constant.Int(2))))
Term.Apply(Term.Ident("foo"), List(Term.Literal(Constant.Int(4))))
Term.Apply(Term.Ident("foo"), List(Term.Literal(Constant.Int(3))))
13 changes: 13 additions & 0 deletions tests/run/i5119b/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 {

inline def ff(arg1: Any, arg2: Any): String = ~Macro.impl('(arg1), '(arg2))

def impl(arg1: Expr[Any], arg2: Expr[Any])(implicit tasty: Tasty): Expr[String] = {
import tasty._
(arg1.toTasty.underlyingArgument.show + "\n" + arg2.toTasty.underlyingArgument.show).toExpr
}

}
11 changes: 11 additions & 0 deletions tests/run/i5119b/Main_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

object Test {
import Macro._

def main(args: Array[String]): Unit = {
println(ff(arg1 = foo(1), arg2 = foo(2)))
println(ff(arg2 = foo(3), arg1 = foo(4)))
}

def foo(x: Any): Any = ()
}
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