Skip to content

Add missing QuoteContext to Liftable.toExpr #6785

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

Merged
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
12 changes: 7 additions & 5 deletions docs/docs/reference/metaprogramming/macros.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,9 @@ The `toExpr` extension method is defined in package `quoted`:
```scala
package quoted

delegate LiftingOps {
def (x: T) toExpr[T] given (ev: Liftable[T]): Expr[T] = ev.toExpr(x)
delegate ExprOps {
def (x: T) toExpr[T: Liftable] given QuoteContext: Expr[T] = the[Liftable[T]].toExpr(x)
...
}
```
The extension says that values of types implementing the `Liftable` type class can be
Expand All @@ -269,15 +270,16 @@ knowing anything about the representation of `Expr` trees. For
instance, here is a possible instance of `Liftable[Boolean]`:
```scala
delegate for Liftable[Boolean] {
def toExpr(b: Boolean) = if (b) '{ true } else '{ false }
def toExpr(b: Boolean) given QuoteContext: Expr[Boolean] =
if (b) '{ true } else '{ false }
}
```
Once we can lift bits, we can work our way up. For instance, here is a
possible implementation of `Liftable[Int]` that does not use the underlying
tree machinery:
```scala
delegate for Liftable[Int] {
def toExpr(n: Int): Expr[Int] = n match {
def toExpr(n: Int) given QuoteContext: Expr[Int] = n match {
case Int.MinValue => '{ Int.MinValue }
case _ if n < 0 => '{ - ${ toExpr(-n) } }
case 0 => '{ 0 }
Expand All @@ -290,7 +292,7 @@ Since `Liftable` is a type class, its instances can be conditional. For example,
a `List` is liftable if its element type is:
```scala
delegate [T: Liftable] for Liftable[List[T]] {
def toExpr(xs: List[T]): Expr[List[T]] = xs match {
def toExpr(xs: List[T]) given QuoteContext: Expr[List[T]] = xs match {
case head :: tail => '{ ${ toExpr(head) } :: ${ toExpr(tail) } }
case Nil => '{ Nil: List[T] }
}
Expand Down
1 change: 0 additions & 1 deletion docs/docs/reference/metaprogramming/tasty-reflect.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ is used.

```scala
import scala.quoted._
import scala.tasty._

inline def natConst(x: => Int): Int = ${natConstImpl('{x})}

Expand Down
4 changes: 2 additions & 2 deletions library/src-3.x/scala/quoted/Liftable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import scala.runtime.quoted.Unpickler.liftedExpr
* without going through an explicit `'{...}` operation.
*/
abstract class Liftable[T] {
def toExpr(x: T): Expr[T]
def toExpr(x: T) given QuoteContext: Expr[T]
}

/** Some liftable base types. To be completed with at least all types
Expand All @@ -27,7 +27,7 @@ object Liftable {
implicit def ClassIsLiftable[T]: Liftable[Class[T]] = new PrimitiveLiftable

private class PrimitiveLiftable[T] extends Liftable[T] {
override def toExpr(x: T): Expr[T] = liftedExpr(x)
override def toExpr(x: T) given QuoteContext: Expr[T] = liftedExpr(x)
}

}
4 changes: 2 additions & 2 deletions library/src-3.x/scala/quoted/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ package object quoted {
private object NoResult

object autolift {
implicit def autoToExpr[T: Liftable](x: T): Expr[T] = x.toExpr
implicit def autoToExpr[T: Liftable](x: T) given QuoteContext: Expr[T] = x.toExpr
}

implicit object ExprOps {
def (x: T) toExpr[T] given Liftable[T]: Expr[T] = the[Liftable[T]].toExpr(x)
def (x: T) toExpr[T: Liftable] given QuoteContext: Expr[T] = the[Liftable[T]].toExpr(x)

def (list: List[Expr[T]]) toExprOfList[T] given Type[T]: Expr[List[T]] = list match {
case x :: xs => '{ $x :: ${xs.toExprOfList} }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package dotty.internal

import scala.quoted._
import scala.quoted.matching._
import scala.tasty.Reflection
import reflect._

object StringContextMacro {
Expand Down
1 change: 0 additions & 1 deletion semanticdb/src/dotty/semanticdb/Main.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package dotty.semanticdb

import scala.tasty.Reflection
import scala.tasty.file._
import scala.NotImplementedError

Expand Down
2 changes: 0 additions & 2 deletions semanticdb/src/dotty/semanticdb/TastyScalaFileInferrer.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package dotty.semanticdb

import scala.tasty.Reflection

import scala.meta.internal.{semanticdb => s}
import scala.tasty.Reflection
import scala.tasty.file.TastyConsumer
Expand Down
2 changes: 0 additions & 2 deletions semanticdb/src/dotty/semanticdb/Utils.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package dotty.semanticdb


import scala.tasty.Reflection
import scala.tasty.file._
import scala.collection.mutable.HashMap

Expand All @@ -11,7 +10,6 @@ import java.nio.file._
import scala.meta.internal.{semanticdb => s}
import scala.collection.JavaConverters._
import java.io.File
import scala.tasty.Reflection
import scala.tasty.file.TastyConsumer
import java.lang.reflect.InvocationTargetException

Expand Down
2 changes: 0 additions & 2 deletions semanticdb/test/dotty/semanticdb/Tests.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package dotty.semanticdb

import scala.tasty.Reflection
import scala.tasty.file._
import scala.collection.mutable.HashMap

Expand All @@ -10,7 +9,6 @@ import java.nio.file._
import scala.meta.internal.{semanticdb => s}
import scala.collection.JavaConverters._
import java.io.File
import scala.tasty.Reflection
import scala.tasty.file.TastyConsumer
import java.lang.reflect.InvocationTargetException

Expand Down
3 changes: 1 addition & 2 deletions tests/neg-macros/inline-case-objects/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@

import scala.quoted._
import scala.quoted.autolift._

object Macros {
def impl(foo: Any): Expr[String] = foo.getClass.getCanonicalName
def impl(foo: Any) given QuoteContext: Expr[String] = foo.getClass.getCanonicalName.toExpr
}

class Bar {
Expand Down
12 changes: 6 additions & 6 deletions tests/neg-macros/inline-macro-staged-interpreter/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,29 @@ object E {

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

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

}

trait E[T] {
def lift: Expr[T]
def lift given QuoteContext: Expr[T]
}

case class I(n: Int) extends E[Int] {
def lift: Expr[Int] = n
def lift given QuoteContext: Expr[Int] = n
}

case class Plus[T](x: E[T], y: E[T])(implicit op: Plus2[T]) extends E[T] {
def lift: Expr[T] = op(x.lift, y.lift)
def lift given QuoteContext: Expr[T] = op(x.lift, y.lift)
}

trait Op2[T] {
def apply(x: Expr[T], y: Expr[T]): Expr[T]
def apply(x: Expr[T], y: Expr[T]) given QuoteContext: Expr[T]
}

trait Plus2[T] extends Op2[T]
object Plus2 {
implicit case object IPlus extends Plus2[Int] {
def apply(x: Expr[Int], y: Expr[Int]): Expr[Int] = '{$x + $y}
def apply(x: Expr[Int], y: Expr[Int]) given QuoteContext: Expr[Int] = '{$x + $y}
}
}
5 changes: 2 additions & 3 deletions tests/neg-macros/inline-option/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@

import scala.quoted._
import scala.quoted.autolift._

object Macro {
def impl(opt: Option[Int]): Expr[Int] = opt match {
case Some(i) => i
def impl(opt: Option[Int]) given QuoteContext: Expr[Int] = opt match {
case Some(i) => i.toExpr
case None => '{-1}
}
}
44 changes: 22 additions & 22 deletions tests/neg-macros/inline-tuples-1/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@ import scala.quoted._
import scala.quoted.autolift._

object Macros {
def tup1(tup: Tuple1[Int]): Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum
def tup2(tup: Tuple2[Int, Int]): Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum
def tup3(tup: Tuple3[Int, Int, Int]): Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum
def tup4(tup: Tuple4[Int, Int, Int, Int]): Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum
def tup5(tup: Tuple5[Int, Int, Int, Int, Int]): Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum
def tup6(tup: Tuple6[Int, Int, Int, Int, Int, Int]): Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum
def tup7(tup: Tuple7[Int, Int, Int, Int, Int, Int, Int]): Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum
def tup8(tup: Tuple8[Int, Int, Int, Int, Int, Int, Int, Int]): Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum
def tup9(tup: Tuple9[Int, Int, Int, Int, Int, Int, Int, Int, Int]): Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum
def tup10(tup: Tuple10[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]): Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum
def tup11(tup: Tuple11[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]): Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum
def tup12(tup: Tuple12[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]): Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum
def tup13(tup: Tuple13[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]): Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum
def tup14(tup: Tuple14[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]): Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum
def tup15(tup: Tuple15[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]): Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum
def tup16(tup: Tuple16[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]): Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum
def tup17(tup: Tuple17[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]): Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum
def tup18(tup: Tuple18[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]): Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum
def tup19(tup: Tuple19[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]): Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum
def tup20(tup: Tuple20[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]): Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum
def tup21(tup: Tuple21[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]): Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum
def tup22(tup: Tuple22[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]): Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum
def tup1(tup: Tuple1[Int]) given QuoteContext: Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum
def tup2(tup: Tuple2[Int, Int]) given QuoteContext: Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum
def tup3(tup: Tuple3[Int, Int, Int]) given QuoteContext: Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum
def tup4(tup: Tuple4[Int, Int, Int, Int]) given QuoteContext: Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum
def tup5(tup: Tuple5[Int, Int, Int, Int, Int]) given QuoteContext: Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum
def tup6(tup: Tuple6[Int, Int, Int, Int, Int, Int]) given QuoteContext: Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum
def tup7(tup: Tuple7[Int, Int, Int, Int, Int, Int, Int]) given QuoteContext: Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum
def tup8(tup: Tuple8[Int, Int, Int, Int, Int, Int, Int, Int]) given QuoteContext: Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum
def tup9(tup: Tuple9[Int, Int, Int, Int, Int, Int, Int, Int, Int]) given QuoteContext: Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum
def tup10(tup: Tuple10[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]) given QuoteContext: Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum
def tup11(tup: Tuple11[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]) given QuoteContext: Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum
def tup12(tup: Tuple12[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]) given QuoteContext: Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum
def tup13(tup: Tuple13[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]) given QuoteContext: Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum
def tup14(tup: Tuple14[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]) given QuoteContext: Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum
def tup15(tup: Tuple15[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]) given QuoteContext: Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum
def tup16(tup: Tuple16[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]) given QuoteContext: Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum
def tup17(tup: Tuple17[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]) given QuoteContext: Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum
def tup18(tup: Tuple18[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]) given QuoteContext: Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum
def tup19(tup: Tuple19[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]) given QuoteContext: Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum
def tup20(tup: Tuple20[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]) given QuoteContext: Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum
def tup21(tup: Tuple21[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]) given QuoteContext: Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum
def tup22(tup: Tuple22[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]) given QuoteContext: Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum
}
4 changes: 2 additions & 2 deletions tests/neg-macros/quote-interpolator-core-old.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ object FInterpolation {
// ...
}

private def liftSeq(args: Seq[Expr[Any]]): Expr[Seq[Any]] = args match {
private def liftSeq(args: Seq[Expr[Any]]) given QuoteContext: Expr[Seq[Any]] = args match {
case x :: xs => '{ ($x) +: ${liftSeq(xs)} }
case Nil => '{Seq(): Seq[Any]}
}

def fInterpolation(sc: StringContext, args: Seq[Expr[Any]]): Expr[String] = {
def fInterpolation(sc: StringContext, args: Seq[Expr[Any]]) given QuoteContext: Expr[String] = {
val str: Expr[String] = sc.parts.mkString("")
val args1: Expr[Seq[Any]] = liftSeq(args)
'{ $str.format($args1: _*) }
Expand Down
2 changes: 1 addition & 1 deletion tests/neg-macros/quote-macro-complex-arg-0.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ 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 }
def bar(x: Int, y: Expr[Int]) given QuoteContext: Expr[Int] = '{ ${x.toExpr} + $y }
}
2 changes: 1 addition & 1 deletion tests/neg-macros/splice-in-top-level-splice-1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ import scala.quoted.autolift._
object Foo {
inline def foo(): Int = ${bar(${x})} // error
def x: Expr[Int] = '{1}
def bar(i: Int): Expr[Int] = i
def bar(i: Int) given QuoteContext: Expr[Int] = i
}
2 changes: 0 additions & 2 deletions tests/neg-macros/tasty-macro-assert-1/quoted_1.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import scala.quoted._

import scala.tasty._

object Asserts {

implicit class Ops[T](left: T) {
Expand Down
2 changes: 0 additions & 2 deletions tests/neg-macros/tasty-macro-assert-2/quoted_1.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import scala.quoted._

import scala.tasty._

object Asserts {

implicit class Ops[T](left: T) {
Expand Down
2 changes: 0 additions & 2 deletions tests/neg-macros/tasty-macro-error/quoted_1.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import scala.quoted._

import scala.tasty._

object Macros {

inline def fun(x: Any): Unit = ${ impl('x) }
Expand Down
2 changes: 0 additions & 2 deletions tests/neg-macros/tasty-macro-positions/quoted_1.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import scala.quoted._

import scala.tasty._

object Macros {

inline def fun(x: Any): Unit = ${ impl('x) }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import scala.quoted._
import scala.tasty.Reflection
import scala.language.implicitConversions

object Macro {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import scala.quoted._
import scala.tasty.Reflection
import scala.language.implicitConversions

object Macro {
Expand Down
1 change: 0 additions & 1 deletion tests/neg-with-compiler/i5941/macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ abstract class Lens[S, T] {
}

import scala.quoted._
import scala.tasty._

object Lens {
def apply[S, T](_get: S => T)(_set: T => S => S): Lens[S, T] = new Lens {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ object Macros {

implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader)
inline def foo(i: => Int): Int = ${ fooImpl('i) }
def fooImpl(i: Expr[Int]): Expr[Int] = {
def fooImpl(i: Expr[Int]) given QuoteContext: Expr[Int] = {
val y: Int = run(i)
y
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import scala.quoted.autolift._
object Macros {

inline def foo(i: => Int): Int = ${ fooImpl('i) }
def fooImpl(i: Expr[Int]): Expr[Int] = {
def fooImpl(i: Expr[Int]) given QuoteContext: Expr[Int] = {
implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader)
val y: Int = run(i)
y
Expand Down
1 change: 0 additions & 1 deletion tests/pending/run/tasty-comments/quoted_1.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import scala.quoted._
import scala.quoted.autolift._

import scala.tasty._

object Macros {

Expand Down
1 change: 0 additions & 1 deletion tests/pos-macros/i6171/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import scala.quoted._
import scala.tasty._

object scalatest {

Expand Down
1 change: 0 additions & 1 deletion tests/pos-macros/i6535/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import scala.quoted._
import scala.tasty._

object scalatest {

Expand Down
4 changes: 2 additions & 2 deletions tests/pos-macros/quote-nested-object/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ object Macro {

inline def plus(inline n: Int, m: Int): Int = ${ plus(n, 'm) }

def plus(n: Int, m: Expr[Int]): Expr[Int] =
def plus(n: Int, m: Expr[Int]) given QuoteContext: Expr[Int] =
if (n == 0) m
else '{ ${n} + $m }

object Implementation2 {

inline def plus(inline n: Int, m: Int): Int = ${ plus(n, 'm) }

def plus(n: Int, m: Expr[Int]): Expr[Int] =
def plus(n: Int, m: Expr[Int]) given QuoteContext: Expr[Int] =
if (n == 0) m
else '{ ${n} + $m }
}
Expand Down
2 changes: 1 addition & 1 deletion tests/pos-macros/quote-whitebox-2/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ object Macro {

inline def charOrString(inline str: String) <: Any = ${ impl(str) }

def impl(str: String) = if (str.length == 1) str.charAt(0).toExpr else str.toExpr
def impl(str: String) given QuoteContext = if (str.length == 1) str.charAt(0).toExpr else str.toExpr

}
Loading