-
Notifications
You must be signed in to change notification settings - Fork 1.1k
quotes.reflect.memberType can return ClassInfo #15159
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
The macro is trying to select the member |
Fixes scala#15159 Updates buggy tests of scala#13230
@nicolasstucki I tried using the val childTpe = childSymbol.owner.typeRef.memberType(childSymbol) |
@nicolasstucki does this mean that My use-case is trying to get the types of implementations of a |
I'd like to second @adamw's question above. |
This is how @plokhotnyuk is doing it in jsoniter-scala: I refuse to believe that to be the "intended" way. |
Damn. Just now saw #15157, which already contains a lot of the relevant discussion. Apologies for the duplicated content here... 🫤 |
@sirthias Thanks! :) Wow that's indeed complex. How did @plokhotnyuk arrive at that code? ;) Anyway, I think this means that getting I'll try to use the above (with attribution, of course) and we'll see how this works for my use case |
@adamw Yes, the linked snippet from |
I am still working on trying to improve the situation for inner classes (it is non-trivial to construct types with the correct prefix), but for static classes it is comparatively simple - that would be very interesting to extract the logic from Mirror synthesis and expose it as an API You also mentioned that you were not successful extracting the |
Seems that that page is not up to date with the fixes in https://github.com/lampepfl/dotty/blob/main/docs/_docs/reference/contextual/derivation-macro.md |
Thank you, @nicolasstucki, for the pointer to that page! def adtChildren(tpe: TypeRepr): List[TypeRepr] =
tpe.asType match
case '[t] =>
Expr.summon[Mirror.Of[t]].toList.flatMap {
case '{ $m: Mirror.SumOf[t] { type MirroredElemTypes = subs } } => typeReprsOf[subs]
case x => Nil
}
def typeReprsOf[Ts: Type]: List[TypeRepr] =
Type.of[Ts] match
case '[EmptyTuple] => Nil
case '[t *: ts] => TypeRepr.of[t] :: typeReprsOf[ts] No need for a call to |
Fixes scala#15159 Updates buggy tests of scala#13230
Fixes scala#15159 Updates buggy tests of scala#13230
Fixes scala#15159 Updates buggy tests of scala#13230
Fixes scala#15159 Updates buggy tests of scala#13230
Fixes scala#15159 Updates buggy tests of scala#13230
Discussed in #15157
in the example below,
memberType
returns aClassInfo
, which is not exposed in the quotes api, and seems unexpected when pattern matching on a type. It seems thatmemberType
should escape this?Originally posted by adamw May 10, 2022
I'm trying to summon a typeclass instance for each child class of a sealed trait. So far I've got the following code (here simplified):
The
childTpe: TypeRepr
is correct, however I get an exception when converting it to aType
and trying to get a handle to the type parameterc
(so that later I can doExpr.summon[MyTypeClass[c]]
). Using the following invocation:The output is:
Is there a better (and working :) ) way to achieve the above goal?
The text was updated successfully, but these errors were encountered: