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 attached sample code compiles fine in Scala 2.11.7 and Scala 2.10.3 (Scala 2.9.3 warns that "TestMain.scala:9: error: scrutinee is incompatible with pattern type") - even with -unchecked -deprecation -feature -Xfuture -Xfatal-warnings -Xlint compiler options - but prints "ChildA#InnerOne: b.InnerOne" when run, i.e. the match at TestMain:8 matches ChildA#InnerOne although x is ChildB#InnerOne (and thus I'd expect it to print "ChildB#InnerOne: b.InnerOne".
While I think the match should be possible (by type-checking the reference to the outer object) the compiler should at least generate a warning (like it does for matching things like case e:Seq[String]=> ???.
The text was updated successfully, but these errors were encountered:
At 2.13.8, still no outer checking, but compiler overcompensates by warning:
t9484.scala:9: warning: match may not be exhaustive.
It would fail on the following input: (x: Parent#InnerOne forSome x not in (ChildA#InnerOne, ChildB#InnerOne))
x match {
^
The attached test
object TestMain {
def main(args:Array[String]): Unit = {
val b=new ChildB
val x:Parent#InnerOne=new b.InnerOne("b.InnerOne")
matchInnerOne(x)
}
def matchInnerOne(x:Parent#InnerOne):Unit={
x match {
case ao:ChildA#InnerOne⇒ println("ChildA#InnerOne: "+ao.name)
case bo:ChildB#InnerOne⇒ println("ChildB#InnerOne: "+bo.name)
}
}
}
sealed trait Parent {
sealed trait Inner {
def name:String
}
final class InnerOne(val name:String) extends Inner
final class InnerTwo(val name:String) extends Inner
}
class ChildA extends Parent
class ChildB extends Parent
Oh wait, ChildX are not final. OK, same result if final.
The attached sample code compiles fine in Scala 2.11.7 and Scala 2.10.3 (Scala 2.9.3 warns that "TestMain.scala:9: error: scrutinee is incompatible with pattern type") - even with
-unchecked -deprecation -feature -Xfuture -Xfatal-warnings -Xlint
compiler options - but prints "ChildA#InnerOne: b.InnerOne" when run, i.e. the match at TestMain:8 matchesChildA#InnerOne
althoughx
isChildB#InnerOne
(and thus I'd expect it to print "ChildB#InnerOne: b.InnerOne".While I think the match should be possible (by type-checking the reference to the outer object) the compiler should at least generate a warning (like it does for matching things like
case e:Seq[String]=> ???
.The text was updated successfully, but these errors were encountered: