Open
Description
Compiler version
3.6.3
Minimized code
case class CaseClass(a:Int)
case class Error(a:Int)
abstract class fred{
def method:CaseClass | Error
method match {
case t:CaseClass => // use t which is a CaseClass
case e:Error => // use e which is an error
}
def method2:Seq[CaseClass] | Error
method2 match {
case s:Seq[CaseClass] => // issues an unnecessary warning that the class of the elements can not be checked
case e:Error => // use e which is an error
}
method2 match {
case s:Seq[?] => s.asInstanceOf[Seq[CaseClass]] // is needed to let the code here know what type s is
case e:Error =>
}
}
Output
The compiler will issue a warning that the type of the elements of the first call to method2 can not be checked at runtime. Having to use an asInstanceOf to bypass this warning is an admisssion of failure.
Expectation
The compiler should realise that there is no need to check this at runtime as it would not have allowed anything other than CaseClass elements to in the Seq in the implementation of method2.