scala3
scala3 copied to clipboard
Expected Warning not happening when using higher-kinded types
Compiler version
scalac -version $ Scala compiler version 3.4.0 -- Copyright 2002-2024, LAMP/EPFL
Minimized example
trait T[A] {
def v: A
}
trait T2[F[_], A] {
def v: A
}
object doesntWarn {
val x = new T2[Option, Int | String] {
def v: Int | String = "asdf"
}
val y: T2[Option, Int] = x match {
case z: T2[Option, Int] =>
z
}
}
object warns {
val x = new T[Int | String] {
def v: Int | String = "asdf"
}
val y: T[Int] = x match {
case z: T[Int] =>
z
}
}
Output Error/Warning message
-- [E092] Pattern Match Unchecked Warning: Main.scala:26:9 ---------------------
26 | case z: T[Int] =>
| ^
|the type test for T[Int] cannot be checked at runtime because its type arguments can't be determined from T[Int | String]
|
| longer explanation available when compiling with `-explain`
1 warning found
Why this Error/Warning was not helpful
Hello! I am wondering why only the second example warns. Is higher kinded-types messing with something here? Is this expected?
Thanks in advance!
Hello! I am wondering why only the second example warns. Is higher kinded-types messing with something here? Is this expected?
I don't think this is expected. We should investigate why this happens, thanks for reporting @matheussbernardo
same problem here with 3.4.1 i think
....collectFirst{ case c@XResolved[JobTitle.type](_, _) => c}
[warn] | ^
[warn] |the type test for ....XResolved[X.JobTitle.type]
[warn] | cannot be checked at runtime because its type arguments can't be determined from ....XResolved[X]
[warn] |
[warn] | longer explanation available when compiling with `-explain`
final case class XResolved[A <: X](
column: A,
id: String
)
case object JobTitle extends X
funny enough it still appears to work