com-lihaoyi / upickle

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

Fix macro crash when handling sealed case classes #634

Closed nox213 closed 1 month ago

nox213 commented 1 month ago

Fixes #628

Sealed classes can be instantiated directly. Therefore, when generating the typeTag, I included the sealed class itself. This ensures that the macro correctly handles sealed classes without subclasses. To check whether it’s a sealed class and not a trait or abstract class, I used the following condition:

 sealedParents.find(_ == tpe.typeSymbol)

Since trait and abstract class cannot be instantiated, I believe this approach works. However, I could also explicitly check that the symbol is not a trait or an abstract class, if needed.

What do you think?

lihaoyi commented 1 month ago

@nox213 looks great, thanks!