Skip to content

Commit

Permalink
Avoid accidental conversion from ${ x } to x.unary_~ and back
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasstucki committed Feb 21, 2019
1 parent 7d39a1e commit e23bf3c
Show file tree
Hide file tree
Showing 160 changed files with 435 additions and 423 deletions.
6 changes: 3 additions & 3 deletions bench/tests/power-macro/PowerMacro.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import scala.quoted.Expr

object PowerMacro {

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

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

}
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/ast/Desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1319,9 +1319,9 @@ object desugar {
else
Apply(ref(defn.QuotedExpr_applyR), t)
case Splice(expr) =>
Select(expr, nme.UNARY_~)
Select(expr, nme.splice)
case TypSplice(expr) =>
Select(expr, tpnme.UNARY_~)
Select(expr, tpnme.splice)
case InterpolatedString(id, segments) =>
val strs = segments map {
case ts: Thicket => ts.trees.head
Expand Down
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -707,16 +707,16 @@ class Definitions {
def QuotedExprModule(implicit ctx: Context): Symbol = QuotedExprClass.companionModule
lazy val QuotedExpr_applyR: TermRef = QuotedExprModule.requiredMethodRef(nme.apply)
def QuotedExpr_apply(implicit ctx: Context): Symbol = QuotedExpr_applyR.symbol
lazy val QuotedExpr_~ : TermSymbol = QuotedExprClass.requiredMethod(nme.UNARY_~)
lazy val QuotedExpr_splice : TermSymbol = QuotedExprClass.requiredMethod(nme.splice)

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

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

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

lazy val QuotedTypeModuleType: TermRef = ctx.requiredModuleRef("scala.quoted.Type")
def QuotedTypeModule(implicit ctx: Context): Symbol = QuotedTypeModuleType.symbol
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,8 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
if (name.isTypeName) typeText(txt)
else txt
case tree @ Select(qual, name) =>
if (tree.hasType && tree.symbol == defn.QuotedExpr_~) keywordStr("${") ~ toTextLocal(qual) ~ keywordStr("}")
else if (tree.hasType && tree.symbol == defn.QuotedType_~) typeText("${") ~ toTextLocal(qual) ~ typeText("}")
if (tree.hasType && tree.symbol == defn.QuotedExpr_splice) keywordStr("${") ~ toTextLocal(qual) ~ keywordStr("}")
else if (tree.hasType && tree.symbol == defn.QuotedType_splice) typeText("${") ~ toTextLocal(qual) ~ typeText("}")
else if (qual.isType) toTextLocal(qual) ~ "#" ~ typeText(toText(name))
else toTextLocal(qual) ~ ("." ~ nameIdText(tree) provided name != nme.CONSTRUCTOR)
case tree: This =>
Expand Down
8 changes: 4 additions & 4 deletions compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,13 @@ class ReifyQuotes extends MacroTransform {

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

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

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

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

case tree: DefDef if tree.symbol.is(Macro) && level == 0 =>
// Shrink size of the tree. The methods have already been inlined.
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/transform/Staging.scala
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ class Staging extends MacroTransform {
| The access would be accepted with the right type tag, but
| ${ctx.typer.missingArgMsg(tag, reqType, "")}""")
case _ =>
Some(tag.select(tpnme.UNARY_~))
Some(tag.select(tpnme.splice))
}
}
case _ =>
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/transform/SymUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -162,5 +162,5 @@ class SymUtils(val self: Symbol) extends AnyVal {

/** Is symbol a splice operation? */
def isSplice(implicit ctx: Context): Boolean =
self == defn.QuotedExpr_~ || self == defn.QuotedType_~
self == defn.QuotedExpr_splice || self == defn.QuotedType_splice
}
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Implicits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ trait Implicits { self: Typer =>
case t @ TypeRef(NoPrefix, _) =>
inferImplicit(defn.QuotedTypeType.appliedTo(t), EmptyTree, span) match {
case SearchSuccess(tag, _, _) if tag.tpe.isStable =>
tag.tpe.select(defn.QuotedType_~)
tag.tpe.select(defn.QuotedType_splice)
case _ =>
ok = false
t
Expand Down
4 changes: 2 additions & 2 deletions compiler/test-resources/repl/i5551
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
scala> import scala.quoted._

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

scala> inline def assert(expr: => Boolean): Unit = ~ assertImpl('{expr})
scala> inline def assert(expr: => Boolean): Unit = ${ assertImpl('{expr}) }
def assert(expr: => Boolean): Unit

scala> assert(0 == 0)
Expand Down
2 changes: 1 addition & 1 deletion library/src-bootstrapped/scala/quoted/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ package object quoted {
implicit class ListOfExprOps[T](val list: List[Expr[T]]) extends AnyVal {
def toExprOfList(implicit ev: Type[T]): Expr[List[T]] = {
def rec(list: List[Expr[T]]): Expr[List[T]] = list match {
case x :: xs => '{ (~x) :: (~rec(xs)) }
case x :: xs => '{ ($x) :: ${rec(xs)} }
case Nil => '{Nil}
}
rec(list)
Expand Down
6 changes: 4 additions & 2 deletions library/src/scala/quoted/Expr.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package scala.quoted
import scala.runtime.quoted.Unpickler.Pickled

sealed abstract class Expr[+T] {
final def unary_~ : T = throw new Error("~ should have been compiled away")

final def splice: T = throw new Error("splice should have been compiled away")

/** Evaluate the contents of this expression and return the result.
*
Expand All @@ -13,6 +14,7 @@ sealed abstract class Expr[+T] {

/** Show a source code like representation of this expression */
final def show(implicit toolbox: Toolbox): String = toolbox.show(this)

}

object Expr {
Expand Down Expand Up @@ -146,7 +148,7 @@ object Exprs {
// TODO Use a List in FunctionAppliedTo(val f: Expr[_], val args: List[Expr[_]])
// FIXME: Having the List in the code above trigers an assertion error while testing dotty.tools.dotc.reporting.ErrorMessagesTests.i3187
// This test does redefine `scala.collection`. Further investigation is needed.
/** An Expr representing `'{(~f).apply(~x1, ..., ~xn)}` but it is beta-reduced when the closure is known */
/** An Expr representing `'{($f).apply($x1, ..., $xn)}` but it is beta-reduced when the closure is known */
final class FunctionAppliedTo[+R](val f: Expr[_], val args: Array[Expr[_]]) extends Expr[R] {
override def toString: String = s"Expr($f <applied to> ${args.toList})"
}
Expand Down
2 changes: 1 addition & 1 deletion library/src/scala/quoted/Type.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import scala.reflect.ClassTag
import scala.runtime.quoted.Unpickler.Pickled

sealed abstract class Type[T] {
type unary_~ = T
type splice = T
}

/** Some basic type tags, currently incomplete */
Expand Down
2 changes: 1 addition & 1 deletion tests/disabled/run/i4803d/App_2.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ object Test {
}

inline def power2(x: Double) = {
inline def power(x: Double, inline n: Long) = ~PowerMacro.powerCode('{x}, n)
inline def power(x: Double, inline n: Long) = ${ PowerMacro.powerCode('{x}, n) }
power(x, 2)
}
}
4 changes: 2 additions & 2 deletions tests/disabled/run/i4803d/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import scala.quoted._
object PowerMacro {
def powerCode(x: Expr[Double], n: Long): Expr[Double] =
if (n == 0) '{1.0}
else if (n % 2 == 0) '{ val y = $x * $x; ~powerCode('{y}, n / 2) }
else '{ $x * ~powerCode(x, n - 1) }
else if (n % 2 == 0) '{ val y = $x * $x; ${powerCode('{y}, n / 2)} }
else '{ $x * ${powerCode(x, n - 1)} }
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import scala.quoted._
import scala.quoted.Toolbox.Default._

object Macros {
inline def foo(i: => Int): Int = ~fooImpl('{i})
inline def foo(i: => Int): Int = ${ fooImpl('{i}) }
def fooImpl(i: Expr[Int]): Expr[Int] = {
val y: Int = i.run
y.toExpr
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import scala.quoted._
import scala.quoted.Toolbox.Default._

object Macros {
inline def foo(i: => Int): Int = ~fooImpl('{i})
inline def foo(i: => Int): Int = ${ fooImpl('{i}) }
def fooImpl(i: Expr[Int]): Expr[Int] = {
val y: Int = i.run
y.toExpr
Expand Down
4 changes: 2 additions & 2 deletions tests/neg/i4044b.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ class Test {

'{
b // error
~(b)
~('{b}) // error
${b}
${ '{b} } // error
'{ '{$b} } // error
}

Expand Down
4 changes: 2 additions & 2 deletions tests/neg/i4774b.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import scala.quoted._
object Test {
def loop[T](x: Expr[T])(implicit t: Type[T]): Expr[T] = '{
val y: $t = $x;
~loop[$t]( // error
${loop[$t]( // error
'{y}
)
)}
}
}
2 changes: 1 addition & 1 deletion tests/neg/inline-case-objects/Main_2.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ object Test {
println(fooString(bar.Baz)) // error
}

inline def fooString(inline x: Any): String = ~Macros.impl(x)
inline def fooString(inline x: Any): String = ${ Macros.impl(x) }

}
2 changes: 1 addition & 1 deletion tests/neg/inline-macro-staged-interpreter/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import scala.quoted._

object E {

inline def eval[T](inline x: E[T]): T = ~impl(x)
inline def eval[T](inline x: E[T]): T = ${ impl(x) }

def impl[T](x: E[T]): Expr[T] = x.lift

Expand Down
6 changes: 3 additions & 3 deletions tests/neg/inline-option/Main_2.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ object Main {
val b: Option[Int] = Some(4)
size(b) // error

inline def size(inline opt: Option[Int]): Int = ~Macro.impl(opt)
inline def size(inline opt: Option[Int]): Int = ${ Macro.impl(opt) }

inline def size2(inline i: Int): Int = ~Macro.impl(None)
inline def size2(inline i: Int): Int = ${ Macro.impl(None) }

inline def size3(inline i: Int): Int = ~Macro.impl(Some(i))
inline def size3(inline i: Int): Int = ${ Macro.impl(Some(i)) }

}
44 changes: 22 additions & 22 deletions tests/neg/inline-tuples-1/Main_2.scala
Original file line number Diff line number Diff line change
Expand Up @@ -347,27 +347,27 @@ object Test {
)))
}

inline def sum(inline tup: Tuple1[Int]): Int = ~Macros.tup1(tup)
inline def sum(inline tup: Tuple2[Int, Int]): Int = ~Macros.tup2(tup)
inline def sum(inline tup: Tuple3[Int, Int, Int]): Int = ~Macros.tup3(tup)
inline def sum(inline tup: Tuple4[Int, Int, Int, Int]): Int = ~Macros.tup4(tup)
inline def sum(inline tup: Tuple5[Int, Int, Int, Int, Int]): Int = ~Macros.tup5(tup)
inline def sum(inline tup: Tuple6[Int, Int, Int, Int, Int, Int]): Int = ~Macros.tup6(tup)
inline def sum(inline tup: Tuple7[Int, Int, Int, Int, Int, Int, Int]): Int = ~Macros.tup7(tup)
inline def sum(inline tup: Tuple8[Int, Int, Int, Int, Int, Int, Int, Int]): Int = ~Macros.tup8(tup)
inline def sum(inline tup: Tuple9[Int, Int, Int, Int, Int, Int, Int, Int, Int]): Int = ~Macros.tup9(tup)
inline def sum(inline tup: Tuple10[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]): Int = ~Macros.tup10(tup)
inline def sum(inline tup: Tuple11[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]): Int = ~Macros.tup11(tup)
inline def sum(inline tup: Tuple12[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]): Int = ~Macros.tup12(tup)
inline def sum(inline tup: Tuple13[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]): Int = ~Macros.tup13(tup)
inline def sum(inline tup: Tuple14[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]): Int = ~Macros.tup14(tup)
inline def sum(inline tup: Tuple15[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]): Int = ~Macros.tup15(tup)
inline def sum(inline tup: Tuple16[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]): Int = ~Macros.tup16(tup)
inline def sum(inline tup: Tuple17[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]): Int = ~Macros.tup17(tup)
inline def sum(inline tup: Tuple18[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]): Int = ~Macros.tup18(tup)
inline def sum(inline tup: Tuple19[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]): Int = ~Macros.tup19(tup)
inline def sum(inline tup: Tuple20[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]): Int = ~Macros.tup20(tup)
inline def sum(inline tup: Tuple21[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]): Int = ~Macros.tup21(tup)
inline def sum(inline tup: Tuple22[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]): Int = ~Macros.tup22(tup)
inline def sum(inline tup: Tuple1[Int]): Int = ${ Macros.tup1(tup) }
inline def sum(inline tup: Tuple2[Int, Int]): Int = ${ Macros.tup2(tup) }
inline def sum(inline tup: Tuple3[Int, Int, Int]): Int = ${ Macros.tup3(tup) }
inline def sum(inline tup: Tuple4[Int, Int, Int, Int]): Int = ${ Macros.tup4(tup) }
inline def sum(inline tup: Tuple5[Int, Int, Int, Int, Int]): Int = ${ Macros.tup5(tup) }
inline def sum(inline tup: Tuple6[Int, Int, Int, Int, Int, Int]): Int = ${ Macros.tup6(tup) }
inline def sum(inline tup: Tuple7[Int, Int, Int, Int, Int, Int, Int]): Int = ${ Macros.tup7(tup) }
inline def sum(inline tup: Tuple8[Int, Int, Int, Int, Int, Int, Int, Int]): Int = ${ Macros.tup8(tup) }
inline def sum(inline tup: Tuple9[Int, Int, Int, Int, Int, Int, Int, Int, Int]): Int = ${ Macros.tup9(tup) }
inline def sum(inline tup: Tuple10[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]): Int = ${ Macros.tup10(tup) }
inline def sum(inline tup: Tuple11[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]): Int = ${ Macros.tup11(tup) }
inline def sum(inline tup: Tuple12[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]): Int = ${ Macros.tup12(tup) }
inline def sum(inline tup: Tuple13[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]): Int = ${ Macros.tup13(tup) }
inline def sum(inline tup: Tuple14[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]): Int = ${ Macros.tup14(tup) }
inline def sum(inline tup: Tuple15[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]): Int = ${ Macros.tup15(tup) }
inline def sum(inline tup: Tuple16[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]): Int = ${ Macros.tup16(tup) }
inline def sum(inline tup: Tuple17[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]): Int = ${ Macros.tup17(tup) }
inline def sum(inline tup: Tuple18[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]): Int = ${ Macros.tup18(tup) }
inline def sum(inline tup: Tuple19[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]): Int = ${ Macros.tup19(tup) }
inline def sum(inline tup: Tuple20[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]): Int = ${ Macros.tup20(tup) }
inline def sum(inline tup: Tuple21[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]): Int = ${ Macros.tup21(tup) }
inline def sum(inline tup: Tuple22[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]): Int = ${ Macros.tup22(tup) }

}
2 changes: 1 addition & 1 deletion tests/neg/quote-MacroOverride.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ object Test {
}

object B extends A {
inline def f() = ~('{}) // error: may not override
inline def f() = ${'{}} // error: may not override
override def g() = () // error: may not override
}

Expand Down
8 changes: 4 additions & 4 deletions tests/neg/quote-complex-top-splice.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ object Test {
impl(x)
}

inline def foo2: Unit = ~impl({ // error
inline def foo2: Unit = ${ impl({ // error
val x = 1
x
})
}) }

inline def foo3: Unit = ~impl({ // error
inline def foo3: Unit = ${ impl({ // error
println("foo3")
3
})
}) }

inline def foo4: Unit = ${ // error
println("foo4")
Expand Down
4 changes: 2 additions & 2 deletions tests/neg/quote-macro-2-splices.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import scala.quoted._
object Macro {

inline def foo(b: Boolean): Int = { // error
if (b) ~bar(true)
else ~bar(false)
if (b) ${ bar(true) }
else ${ bar(false) }
}

def bar(b: Boolean): Expr[Int] = if (b) '{1} else '{0}
Expand Down
4 changes: 2 additions & 2 deletions tests/neg/quote-macro-complex-arg-0.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import scala.quoted._

object Macros {
inline def foo(inline i: Int, dummy: Int, j: Int): Int = ~bar(i + 1, '{j}) // error: i + 1 is not a parameter or field reference
def bar(x: Int, y: Expr[Int]): Expr[Int] = '{ ~{x.toExpr} + $y }
inline def foo(inline i: Int, dummy: Int, j: Int): Int = ${ bar(i + 1, '{j}) } // error: i + 1 is not a parameter or field reference
def bar(x: Int, y: Expr[Int]): Expr[Int] = '{ ${x.toExpr} + $y }
}
10 changes: 5 additions & 5 deletions tests/neg/quote-macro-splice.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ object Test {

inline def foo1: Int = { // error
println()
~impl(1.toExpr)
${ impl(1.toExpr) }
}

inline def foo2: Int = { // error
~impl(1.toExpr)
~impl(2.toExpr)
${ impl(1.toExpr) }
${ impl(2.toExpr) }
}

inline def foo3: Int = { // error
val a = 1
~impl('{a})
${ impl('{a}) }
}

inline def foo4: Int = { // error
~impl('{1})
${ impl('{1}) }
1
}

Expand Down
2 changes: 1 addition & 1 deletion tests/neg/quote-pcp-in-arg.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import scala.quoted._

object Foo {
inline def foo(x: Int): Int = ~bar('{ '{x}; x }) // error
inline def foo(x: Int): Int = ${ bar('{ '{x}; x }) } // error
def bar(i: Expr[Int]): Expr[Int] = i
}
Loading

0 comments on commit e23bf3c

Please sign in to comment.