The scala compiler should generate warnings for the if statements I've commented on below, but it doesn't. Why?
sealed trait T
object A extends T
val s:Seq[T] = Seq(A)
val result = s.map {
//This if should produce a compiler warning
case a if(a == "A") =>
"First"
case a =>
//This if should produce a compiler warning
if (a == "A") {
"Second"
}
else
{
"Third"
}
}
The result will be "Third" as you'd expect, but the compiler should have generated a warning on the case a if(a == "A")
and on the if (a == "A")
, but alas there is no warning.
If I write the following code it behaves like I would expect:
if(A == "A"){
println("can't happen")
}
// warning: comparing values of types A.type and String using `==' will always yield false
Why is this happening?
Edit: I'm using Scala 2.10.1.
case a:T if(a == "A") =>
and still no warning. – Fenny