-
Notifications
You must be signed in to change notification settings - Fork 21
Open
Labels
fixed in Scala 3This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)
Milestone
Description
The isInstaceOf
check are optimized away in the following situation:
class A
trait T
val casted: A with T = (new A).asInstanceOf[A with T]
casted.isInstanceOf[A with T] // = true
However:
casted.isInstanceOf[A] // = true
casted.isInstanceOf[T] // = false
(fiddle: https://scalafiddle.io/sf/rjfApD5/0)
The check is optimized away and replaced with true
. I am not sure if that is a bug or maybe even desired (optimization) behaviour. However, when using isInstanceOf
I would intuitively have expected a runtime-check no matter what the compiler statically knows.
In any case I would expect the test for T
and for A with T
to both give the same result, be it true or false.
I could reproduce this in both scala 2.11.8 and 2.12.1.
Metadata
Metadata
Assignees
Labels
fixed in Scala 3This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)