Skip to content

Commit 2ca5297

Browse files
committed
Avoid accidental conversion from ${ x } to x.unary_~ and back
1 parent 46c9c1d commit 2ca5297

File tree

160 files changed

+435
-423
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

160 files changed

+435
-423
lines changed

bench/tests/power-macro/PowerMacro.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import scala.quoted.Expr
22

33
object PowerMacro {
44

5-
inline def power(inline n: Long, x: Double) = ~powerCode(n, '{x})
5+
inline def power(inline n: Long, x: Double) = ${powerCode(n, '{x})}
66

77
def powerCode(n: Long, x: Expr[Double]): Expr[Double] =
88
if (n == 0) '{1.0}
9-
else if (n % 2 == 0) '{ val y = ~x * ~x; ~powerCode(n / 2, '{y}) }
10-
else '{ ~x * ~powerCode(n - 1, x) }
9+
else if (n % 2 == 0) '{ val y = $x * $x; ${powerCode(n / 2, '{y})} }
10+
else '{ $x * ${powerCode(n - 1, x)} }
1111

1212
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,9 +1319,9 @@ object desugar {
13191319
else
13201320
Apply(ref(defn.QuotedExpr_applyR), t)
13211321
case Splice(expr) =>
1322-
Select(expr, nme.UNARY_~)
1322+
Select(expr, nme.splice)
13231323
case TypSplice(expr) =>
1324-
Select(expr, tpnme.UNARY_~)
1324+
Select(expr, tpnme.splice)
13251325
case InterpolatedString(id, segments) =>
13261326
val strs = segments map {
13271327
case ts: Thicket => ts.trees.head

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -707,16 +707,16 @@ class Definitions {
707707
def QuotedExprModule(implicit ctx: Context): Symbol = QuotedExprClass.companionModule
708708
lazy val QuotedExpr_applyR: TermRef = QuotedExprModule.requiredMethodRef(nme.apply)
709709
def QuotedExpr_apply(implicit ctx: Context): Symbol = QuotedExpr_applyR.symbol
710-
lazy val QuotedExpr_~ : TermSymbol = QuotedExprClass.requiredMethod(nme.UNARY_~)
710+
lazy val QuotedExpr_splice : TermSymbol = QuotedExprClass.requiredMethod(nme.splice)
711711

712712
lazy val QuotedExprsModule: TermSymbol = ctx.requiredModule("scala.quoted.Exprs")
713713
def QuotedExprsClass(implicit ctx: Context): ClassSymbol = QuotedExprsModule.asClass
714714

715715
lazy val QuotedTypeType: TypeRef = ctx.requiredClassRef("scala.quoted.Type")
716716
def QuotedTypeClass(implicit ctx: Context): ClassSymbol = QuotedTypeType.symbol.asClass
717717

718-
lazy val QuotedType_spliceR: TypeRef = QuotedTypeClass.requiredType(tpnme.UNARY_~).typeRef
719-
def QuotedType_~ : Symbol = QuotedType_spliceR.symbol
718+
lazy val QuotedType_spliceR: TypeRef = QuotedTypeClass.requiredType(tpnme.splice).typeRef
719+
def QuotedType_splice : Symbol = QuotedType_spliceR.symbol
720720

721721
lazy val QuotedTypeModuleType: TermRef = ctx.requiredModuleRef("scala.quoted.Type")
722722
def QuotedTypeModule(implicit ctx: Context): Symbol = QuotedTypeModuleType.symbol

compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,8 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
328328
if (name.isTypeName) typeText(txt)
329329
else txt
330330
case tree @ Select(qual, name) =>
331-
if (tree.hasType && tree.symbol == defn.QuotedExpr_~) keywordStr("${") ~ toTextLocal(qual) ~ keywordStr("}")
332-
else if (tree.hasType && tree.symbol == defn.QuotedType_~) typeText("${") ~ toTextLocal(qual) ~ typeText("}")
331+
if (tree.hasType && tree.symbol == defn.QuotedExpr_splice) keywordStr("${") ~ toTextLocal(qual) ~ keywordStr("}")
332+
else if (tree.hasType && tree.symbol == defn.QuotedType_splice) typeText("${") ~ toTextLocal(qual) ~ typeText("}")
333333
else if (qual.isType) toTextLocal(qual) ~ "#" ~ typeText(toText(name))
334334
else toTextLocal(qual) ~ ("." ~ nameIdText(tree) provided name != nme.CONSTRUCTOR)
335335
case tree: This =>

compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,13 @@ class ReifyQuotes extends MacroTransform {
129129

130130
def mkTagSymbolAndAssignType(spliced: TermRef): TypeDef = {
131131
val splicedTree = tpd.ref(spliced)
132-
val rhs = transform(splicedTree.select(tpnme.UNARY_~))
132+
val rhs = transform(splicedTree.select(tpnme.splice))
133133
val alias = ctx.typeAssigner.assignType(untpd.TypeBoundsTree(rhs, rhs), rhs, rhs)
134134
val local = ctx.newSymbol(
135135
owner = ctx.owner,
136136
name = UniqueName.fresh((splicedTree.symbol.name.toString + "$_~").toTermName).toTypeName,
137137
flags = Synthetic,
138-
info = TypeAlias(splicedTree.tpe.select(tpnme.UNARY_~)),
138+
info = TypeAlias(splicedTree.tpe.select(tpnme.splice)),
139139
coord = spliced.termSymbol.coord).asType
140140

141141
ctx.typeAssigner.assignType(untpd.TypeDef(local.name, alias), local)
@@ -353,11 +353,11 @@ class ReifyQuotes extends MacroTransform {
353353

354354
case tree: TypeTree if tree.tpe.typeSymbol.isSplice =>
355355
val splicedType = tree.tpe.stripTypeVar.asInstanceOf[TypeRef].prefix.termSymbol
356-
transformSplice(ref(splicedType).select(tpnme.UNARY_~).withSpan(tree.span))
356+
transformSplice(ref(splicedType).select(tpnme.splice).withSpan(tree.span))
357357

358358
case tree: RefTree if isCaptured(tree.symbol, level) =>
359359
val t = capturers(tree.symbol).apply(tree)
360-
transformSplice(t.select(if (tree.isTerm) nme.UNARY_~ else tpnme.UNARY_~))
360+
transformSplice(t.select(if (tree.isTerm) nme.splice else tpnme.splice))
361361

362362
case tree: DefDef if tree.symbol.is(Macro) && level == 0 =>
363363
// Shrink size of the tree. The methods have already been inlined.

compiler/src/dotty/tools/dotc/transform/Staging.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ class Staging extends MacroTransform {
301301
| The access would be accepted with the right type tag, but
302302
| ${ctx.typer.missingArgMsg(tag, reqType, "")}""")
303303
case _ =>
304-
Some(tag.select(tpnme.UNARY_~))
304+
Some(tag.select(tpnme.splice))
305305
}
306306
}
307307
case _ =>

compiler/src/dotty/tools/dotc/transform/SymUtils.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,5 +162,5 @@ class SymUtils(val self: Symbol) extends AnyVal {
162162

163163
/** Is symbol a splice operation? */
164164
def isSplice(implicit ctx: Context): Boolean =
165-
self == defn.QuotedExpr_~ || self == defn.QuotedType_~
165+
self == defn.QuotedExpr_splice || self == defn.QuotedType_splice
166166
}

compiler/src/dotty/tools/dotc/typer/Implicits.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ trait Implicits { self: Typer =>
669669
case t @ TypeRef(NoPrefix, _) =>
670670
inferImplicit(defn.QuotedTypeType.appliedTo(t), EmptyTree, span) match {
671671
case SearchSuccess(tag, _, _) if tag.tpe.isStable =>
672-
tag.tpe.select(defn.QuotedType_~)
672+
tag.tpe.select(defn.QuotedType_splice)
673673
case _ =>
674674
ok = false
675675
t

compiler/test-resources/repl/i5551

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
scala> import scala.quoted._
22

3-
scala> def assertImpl(expr: Expr[Boolean]) = '{ if !(~expr) then throw new AssertionError("failed assertion")}
3+
scala> def assertImpl(expr: Expr[Boolean]) = '{ if !($expr) then throw new AssertionError("failed assertion")}
44
def assertImpl(expr: quoted.Expr[Boolean]): quoted.Expr[Unit]
55

6-
scala> inline def assert(expr: => Boolean): Unit = ~ assertImpl('{expr})
6+
scala> inline def assert(expr: => Boolean): Unit = ${ assertImpl('{expr}) }
77
def assert(expr: => Boolean): Unit
88

99
scala> assert(0 == 0)

library/src-bootstrapped/scala/quoted/package.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ package object quoted {
99
implicit class ListOfExprOps[T](val list: List[Expr[T]]) extends AnyVal {
1010
def toExprOfList(implicit ev: Type[T]): Expr[List[T]] = {
1111
def rec(list: List[Expr[T]]): Expr[List[T]] = list match {
12-
case x :: xs => '{ (~x) :: (~rec(xs)) }
12+
case x :: xs => '{ ($x) :: ${rec(xs)} }
1313
case Nil => '{Nil}
1414
}
1515
rec(list)

0 commit comments

Comments
 (0)