-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expr.summon
does not resolve opaque types
#21199
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
Sounds like it's the same with |
Also another thing I experimented with to make it even simplier: import scala.quoted.*
import types.Hello
inline def summonHello: Hello = ${ summonHelloImpl }
private def summonHelloImpl(using Quotes): Expr[Hello] =
import quotes.reflect.*
Symbol.requiredModule("types").typeMember("Hello").typeRef.asType match
case '[t] => Expr.summon[t].getOrElse(report.errorAndAbort(s"Cannot summon a value of type ${TypeRepr.of[Hello]}")).asExprOf[Hello] and: object types:
opaque type Hello = String
def Hello(s: String): Hello = s
import types.*
@main def run =
given Hello = Hello("dummy")
println(summonHello) Which fails with:
|
seems pretty clearly broken, thanks for the minimisation |
Thanks. case '[t] => Expr.summon[t].getOrElse(report.errorAndAbort(s"Cannot summon a value of type ${TypeRepr.of[Hello]}")).asExprOf[Hello] by case '[t] => Expr.summon[t].getOrElse(report.errorAndAbort(s"Cannot summon a value of type ${TypeRepr.of[t]}")).asExprOf[Hello] then it prints:
So that means it looks for a |
Here another conclusion: import scala.quoted.*
import types.Hello
inline def summonHello: Hello = ${ summonHelloImpl }
private def summonHelloImpl(using Quotes): Expr[Hello] =
import quotes.reflect.*
val tpe = Symbol.requiredPackage("types").typeMember("Hello").typeRef
val value = Implicits.search(tpe) match
case iss: ImplicitSearchSuccess => Some(iss.tree.asExprOf[Hello])
case isf: ImplicitSearchFailure => None
value.getOrElse(report.errorAndAbort(s"Cannot summon a value of type ${tpe.typeSymbol.fullName} - ${tpe}")) and: package types:
opaque type Hello = String
object Hello:
def apply(s: String): Hello = s
given Hello = Hello("dummy") // Some instance in the companion object
import types.*
@main def run =
// import Hello.given // Uncomment this line and it works
println(summonHello) Fails to resolve the implicit but with an import of the givens from the companion object, it works. |
Also: val tpe = Symbol.requiredPackage("types").typeMember("MyCaseClass").typeRef
println(tpe.typeSymbol.companionModule.exists.toString) Would return |
BTW I'm happy to look into this issue but not sure where to start from. |
Compiler version
Issue reproduced in
3.4.2
and3.5.0-RC4
.Minimized code
Please check the min repro repo https://github.com/joan38/macro-summon-bug
Output
Gives only
MyCaseClass
instances (not sure why 3 times but that's a different issue):Expectation
Expr.summon[t]
should resolve opaque type too:Thanks
The text was updated successfully, but these errors were encountered: