question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is it possible to read parameterized/polymorphic case classes ?

See original GitHub issue

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:closed
  • Created 9 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
ForNeVeRcommented, Aug 8, 2015

@lihaoyi I think that should be mentioned in the documentation.

0reactions
l15k4commented, Sep 5, 2014

@lihaoyi you were right, I must have made a mistake somewhere else.

def poly[T: Reader](whatever: String): T = read[T](whatever)

is really valid.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found