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
The following code produces no warning, even though the case _ is unreachable since Bar returns an instance of Some (scalac correctly produces a warning here):
objectBar {
defunapply(x: Int):Some[Int] =Some(0)
}
objectTest {
deftest(x: Int) =
x match {
caseBar(a) => a
case _ => x // should be unreachable
}
}
Interestingly, if we replace Int by a sealed trait, we do produce a warning:
sealedtraitBasecaseclassOne() extendsBaseobjectFoo {
defunapply(x: Base):Some[Int] =Some(0)
}
objectTest {
deftest(x: Base) =
x match {
caseFoo(a) => a
case _ => x
}
}
-- [E030] MatchcaseUnreachableWarning:try/some.scala:12:13-----------------12|case _ => x
|^^^^| unreachable code
The text was updated successfully, but these errors were encountered:
The following code produces no warning, even though the
case _
is unreachable sinceBar
returns an instance ofSome
(scalac correctly produces a warning here):Interestingly, if we replace
Int
by a sealed trait, we do produce a warning:The text was updated successfully, but these errors were encountered: