ClassCastException when using Union type with case object and TypeTest #22950
Labels
area:union-types
Issues tied to union types.
itype:bug
itype:soundness
Soundness bug (it lets us compile code that crashes at runtime with a ClassCastException)
Compiler version
3.6.4
Minimized code
I'm building a toy typeclass (named
Typeclass
) and I want it to support Union types, so I wrote acombine
method that takes aTypeclass[A]
and aTypeclass[B]
and returns aTypeclass[A | B]
. I'm usingTypeTest
to be able to match the type at compile time.When declaring a Typeclass instance for a case object, this sample code compiles correctly but generates a
ClassCastException
.Output
By running
scala-cli -S 3.6.4 classCastException.sc
, I get:Expectation
Workaround
If a declare
typeclass
by switchingCaseClassA
andCaseObject
typeclass instances, there's no exception and it gives the correct resultThe text was updated successfully, but these errors were encountered: