Skip to content

ClassCastException when summoning Mirror for hierarchical sum compiled by 3.0.x #13777

Closed
@bishabosha

Description

@bishabosha

Compiler version

3.1.0

Minimized code

compile with Scala 3.0.2 to out dir

sealed trait Top
object Top // companion is necessary

case class Middle() extends Top with Bottom
sealed trait Bottom extends Top

compile with Scala 3.1.0 and with out on classpath

val m = summon[deriving.Mirror.SumOf[Top]]

Output

runtime error:

java.lang.ClassCastException: Top$ cannot be cast to scala.deriving.Mirror$Sum
  ... 28 elided

This happens because Top is an eligible sum, and it has a companion object (which if compiled by Scala 3.1.0 would extend deriving.Mirror.Sum), so the companion object is used as the mirror and is cast to Sum.

Expectation

prevent summoning mirrors for hierarchical sums with companion objects compiled before 3.1.0

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions