Skip to content

Commit e205e6b

Browse files
committed
Fix #5119: Get underlying argument for synthetic local values
1 parent 2b73f9d commit e205e6b

File tree

6 files changed

+32
-5
lines changed

6 files changed

+32
-5
lines changed

compiler/src/dotty/tools/dotc/ast/tpd.scala

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -942,11 +942,14 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
942942
}
943943
}
944944

945-
/** Map Inlined nodes and InlineProxy references to underlying arguments */
945+
/** Map Inlined nodes, InlineProxy references and Synthetic val references to underlying arguments */
946946
object mapToUnderlying extends TreeMap {
947947
override def transform(tree: Tree)(implicit ctx: Context): Tree = tree match {
948-
case tree: Ident if tree.symbol.is(InlineProxy) =>
949-
tree.symbol.defTree.asInstanceOf[ValOrDefDef].rhs.underlyingArgument
948+
case tree: Ident if tree.symbol.is(InlineProxy) || (tree.symbol.is(Synthetic) && !tree.symbol.owner.isClass) =>
949+
tree.symbol.defTree match {
950+
case defTree: ValOrDefDef => defTree.rhs.underlyingArgument
951+
case _ => tree
952+
}
950953
case Inlined(_, _, arg) =>
951954
arg.underlyingArgument
952955
case tree =>

compiler/test/dotc/run-test-pickling.blacklist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ i4803d
2020
i4803e
2121
i4803f
2222
i4947b
23+
i5119
2324
inline-varargs-1
2425
implicitShortcut
2526
lazy-implicit-lists.scala

tests/run/i5119.check

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
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)))
2+
Term.Typed(Term.Repeated(List(Term.Literal(Constant.Int(1)))), TypeTree.Synthetic())

tests/run/i5119/Macro_1.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import scala.quoted._
2+
import scala.tasty.Tasty
3+
4+
object Macro {
5+
class StringContextOps(sc: => StringContext) {
6+
inline def ff(args: => Any*): String = ~Macro.impl('(sc), '(args))
7+
}
8+
implicit inline def XmlQuote(sc: => StringContext): StringContextOps = new StringContextOps(sc)
9+
def impl(sc: Expr[StringContext], args: Expr[Seq[Any]])(implicit tasty: Tasty): Expr[String] = {
10+
import tasty._
11+
(sc.toTasty.underlyingArgument.show + "\n" + args.toTasty.underlyingArgument.show).toExpr
12+
}
13+
}

tests/run/i5119/Main_2.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
object Test {
3+
import Macro._
4+
5+
def main(args: Array[String]): Unit = {
6+
println(ff"Hello World ${1}!")
7+
}
8+
}

tests/run/xml-interpolation/Test_2.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import XmlQuote._
22

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

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

0 commit comments

Comments
 (0)