Skip to content
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

Runtime MatchError if a type alias and its ReaderWriter are defined #289

Open
Governa opened this issue Oct 17, 2019 · 0 comments
Open

Runtime MatchError if a type alias and its ReaderWriter are defined #289

Governa opened this issue Oct 17, 2019 · 0 comments

Comments

@Governa
Copy link

Governa commented Oct 17, 2019

This is not exactly a bug, it is kind of a feature request.

If I create an "alias" of a type and proceed to create a ReadWriter to the alias, the program compiles but fails on with scala.MatchError on runtime while serializing an object of the aliased type.

In my use case it, the problematic type was used in a case class with an default value, so it would only fail in the rare cases where the default value was not used.

Bellow is the simplest reproduction of the problem I could manage to create.

import upickle.default.{ReadWriter, Writer, macroRW, write}
import scala.util.Try

object Example {
  type Problem = List[Int]
  final case class A(x: Problem = List()) extends AnyVal
  implicit val ARw: ReadWriter[A] = macroRW
  implicit val XRw: ReadWriter[Problem] = macroRW // Not needed, and if commented out solves the MatchError.

  def main(args: Array[String]) {

    def serialize[T](data: T)(implicit writer: Writer[T]): String = {
      write(data)
    }

    println(A()) // OK
    println(A(List())) // OK
    println(Try(serialize(A(List(0, 1))))) // scala.MatchError
    println(Try(serialize(List(0, 1).asInstanceOf[Problem]))) // scala.MatchError
  }
}
@Governa Governa changed the title Runtime MatchError if a type and its ReaderWriter are defined Runtime MatchError if a type alias and its ReaderWriter are defined Oct 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant