diff --git a/compiler/src/dotty/tools/dotc/ast/tpd.scala b/compiler/src/dotty/tools/dotc/ast/tpd.scala index ffa501ce7181..471350ba3d03 100644 --- a/compiler/src/dotty/tools/dotc/ast/tpd.scala +++ b/compiler/src/dotty/tools/dotc/ast/tpd.scala @@ -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) } } diff --git a/compiler/test/dotc/run-test-pickling.blacklist b/compiler/test/dotc/run-test-pickling.blacklist index f6a0edc4e7f5..39680daf65f8 100644 --- a/compiler/test/dotc/run-test-pickling.blacklist +++ b/compiler/test/dotc/run-test-pickling.blacklist @@ -20,6 +20,8 @@ i4803d i4803e i4803f i4947b +i5119 +i5119b inline-varargs-1 implicitShortcut lazy-implicit-lists.scala diff --git a/tests/run/i5119.check b/tests/run/i5119.check new file mode 100644 index 000000000000..8ceb3b582ff2 --- /dev/null +++ b/tests/run/i5119.check @@ -0,0 +1,2 @@ +Term.Select(Term.Apply(Term.Select(Term.New(TypeTree.TypeIdent("StringContextOps")), "", 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()) diff --git a/tests/run/i5119/Macro_1.scala b/tests/run/i5119/Macro_1.scala new file mode 100644 index 000000000000..bbcd4da86104 --- /dev/null +++ b/tests/run/i5119/Macro_1.scala @@ -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 + } +} diff --git a/tests/run/i5119/Main_2.scala b/tests/run/i5119/Main_2.scala new file mode 100644 index 000000000000..9242dcabc5b1 --- /dev/null +++ b/tests/run/i5119/Main_2.scala @@ -0,0 +1,8 @@ + +object Test { + import Macro._ + + def main(args: Array[String]): Unit = { + println(ff"Hello World ${1}!") + } +} \ No newline at end of file diff --git a/tests/run/i5119b.check b/tests/run/i5119b.check new file mode 100644 index 000000000000..29e18e92d65b --- /dev/null +++ b/tests/run/i5119b.check @@ -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)))) diff --git a/tests/run/i5119b/Macro_1.scala b/tests/run/i5119b/Macro_1.scala new file mode 100644 index 000000000000..4521a5ca9317 --- /dev/null +++ b/tests/run/i5119b/Macro_1.scala @@ -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 + } + +} diff --git a/tests/run/i5119b/Main_2.scala b/tests/run/i5119b/Main_2.scala new file mode 100644 index 000000000000..e6a797d97dca --- /dev/null +++ b/tests/run/i5119b/Main_2.scala @@ -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 = () +} diff --git a/tests/run/xml-interpolation/Test_2.scala b/tests/run/xml-interpolation/Test_2.scala index 6dda8d1a00d7..9a3d8d64161b 100644 --- a/tests/run/xml-interpolation/Test_2.scala +++ b/tests/run/xml-interpolation/Test_2.scala @@ -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)))