You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[warn] -- Unchecked Warning: ...src/main/scala/Main.scala:7:9
[warn] 7 | case IArray() => println("Empty")
[warn] | ^
[warn] | the type test for IArray[Any] cannot be checked at runtime
[warn] -- [E030] Match case Unreachable Warning: ...src/main/scala/Main.scala:8:9
[warn] 8 | case IArray(i: String) => println("Caught")
[warn] | ^^^^^^^^^^^^^^^^^
[warn] | Unreachable case
Result of running:
Empty
Caught
Failure
Expectation
Based on the runtime result i would say both warnings were not expected. The question remains if the opaque type IArray should match a normal Array at all. Probably it would do no harm, but it is somewhat counter intuitive, since IArray is derived from Array and not the other way around.
Discussion
I am uncertain if this qualifies as compiler bug or not.
If you compile with the option -source:future, Scastie link, the Unreachable Warning is replaced by an Unmatchable Type Warning, which indeed is more adequate. The question if an immutable type should be unmatchable should be discussed an other time.
The text was updated successfully, but these errors were encountered:
Observation
Compile and run the code with Scala 3.1.1: Scastie link
Result of compilation:
Result of running:
Expectation
Based on the runtime result i would say both warnings were not expected. The question remains if the opaque type
IArray
should match a normalArray
at all. Probably it would do no harm, but it is somewhat counter intuitive, sinceIArray
is derived fromArray
and not the other way around.Discussion
-source:future
, Scastie link, the Unreachable Warning is replaced by an Unmatchable Type Warning, which indeed is more adequate. The question if an immutable type should be unmatchable should be discussed an other time.The text was updated successfully, but these errors were encountered: