-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Symbol.asQuotes doesn't populate the implicit scope #22260
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
Comments
Hi! I see the |
That's how it works currently but that's a departure from normal Scala giving special semantics to macros. In a sense, quasi-quotes in Scala 2 emulated better code you would write by hand. |
@jchyb consider this (same applies for the reflection API) import scala.quoted.*
object Macros:
inline def inMethod: Int = ${ insideMethod }
inline def usMethod: Int = ${ usingMethod }
inline def inObject: Int = ${ insideObject }
inline def inClass: Int = ${ insideClass }
inline def usClass: Int = ${ usingClass }
def insideMethod(using Quotes): Expr[Int] = '{
def foo =
given Int = 42
${ Expr.summon[Int].getOrElse('{ 0 }) /* does not work */ }
foo
}
def usingMethod(using Quotes): Expr[Int] = '{
def foo(using Int) =
${ Expr.summon[Int].getOrElse('{ 0 }) /* does not work */ }
foo(using 42)
}
def insideObject(using Quotes): Expr[Int] = '{
object Foo:
given Int = 42
val x = ${ Expr.summon[Int].getOrElse('{ 0 }) /* works */ }
Foo.x
}
def insideClass(using Quotes): Expr[Int] = '{
class Foo:
given Int = 42
val x = ${ Expr.summon[Int].getOrElse('{ 0 }) /* works */ }
new Foo().x
}
def usingClass(using Quotes): Expr[Int] = '{
class Foo(using Int):
val x = ${ Expr.summon[Int].getOrElse('{ 0 }) /* works */ }
new Foo(using 42).x
}
object Test:
@main def go =
println(Macros.inMethod) // prints 0
println(Macros.usMethod) // prints 0
println(Macros.inObject) // prints 42
println(Macros.inClass) // prints 42
println(Macros.usClass) // prints 42
|
Here I mean literally |
Uh oh!
There was an error while loading. Please reload this page.
Compiler version
3.6.2
Minimized code
Output
Expectation
Symbol.asQuotes
should populate the implicit scope.Real world use-case: typelevel/cats-tagless#588
See the hack that I had to do (
refs
here are the implicit parameters of the method owning the quotesq
):The text was updated successfully, but these errors were encountered: