Is it possible to read parameterized/polymorphic case classes ?
See original GitHub issueIssue Description
I’m sorry for flooding upicke with issues 😃 But I got utterly stuck on reading :
case class What[E](a: TypeThatHasAReaderAvailable[E])
read[What[Ever]](xyz)
The problem is here : https://github.com/lihaoyi/upickle/blob/ccd23c491ebec51a091ffc49b709d067fa1c1df8/shared/main/scala/upickle/Macros.scala#L121
[info] exception during macro expansion:
[info] scala.ScalaReflectionException: value apply encapsulates multiple overloaded alternatives and cannot be treated as a method. Consider invoking `<offending symbol>.asTerm.alternatives` and manually picking the required method
[info] at scala.reflect.api.Symbols$SymbolApi$class.asMethod(Symbols.scala:228)
[info] at scala.reflect.internal.Symbols$SymbolContextApiImpl.asMethod(Symbols.scala:82)
[info] at upickle.Macros$.picklerFor(Macros.scala:121)
[info] at upickle.Macros$.macroRImpl(Macros.scala:32)
[info] val res = read[ResponseMessage[Vertex]](x.data.toString)
[info]
I tried even invoke the macro supplying the type parameters directly to it, but it failed the same way :
import scala.language.experimental.macros
def macroR[T]: Reader[T] = macro Macros.macroRImpl[T]
val a = macroR[What[Ever]]
Would you please give me a hint here?
Issue Analytics
- State:
- Created 9 years ago
- Comments:7 (6 by maintainers)
Top Results From Across the Web
Is it possible to read parameterized/polymorphic case classes
To my knowledge, that would work only if you provided it with dedicated Reader[YourCaseClass] in your scope. Otherwise it falls back to your ......
Read more >scala - How to handle simple polymorphism with case classes?
Rightfold answer was close, what you have are not really functions but singleton types: scala> case class A() defined class A scala> A...
Read more >CS312 Lecture 4 Polymorphism and Parameterized Types
A parameterized datatype is a recipe for creating a family of related datatypes. The type variable 'a is a type parameter for which...
Read more >Ad-hoc polymorphism and type classes | by Sinisa Louc
Conceptual and practical explanation of ad-hoc polymorphism and type classes, with implementations in Scala.
Read more >Parametric Polymorphism and Generics
e.g. a private method is not accessible to calls from outside the class ... Explicit parametric polymorphism is also known as genericity.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@lihaoyi I think that should be mentioned in the documentation.
@lihaoyi you were right, I must have made a mistake somewhere else.
is really valid.