com-lihaoyi / upickle

uPickle: a simple, fast, dependency-free JSON & Binary (MessagePack) serialization library for Scala
https://com-lihaoyi.github.io/upickle
MIT License
707 stars 158 forks source link

Fix ClassCastException on import given #472

Closed lihaoyi closed 1 year ago

lihaoyi commented 1 year ago

Fixes https://github.com/com-lihaoyi/upickle/issues/469

The basic problem is that superTypeReader and superTypeWriter were triggering for Types T and V which were identical, meaning it was getting used even when not necessary due to import upickle.default.given increasing its implicit priority.

This PR adds a : SumOf implicit requirement to V, ensuring that superTypeReader and superTypeWriter only trigger when V is a parent sealed trait/class/enum type, won't trigger when T =:= V as a case class, and thus the .asInstanceOf[TaggedReader[T]] cast is valid