Aladdin - Scala Bugtracking
[#215] project: compiler priority: low category: missing feature
submitter assigned to status date submitted
Vincent Martin won't fix 2003-11-04 17:00:00.0
subject "case sensitive" typechecking
code
object caseTest {  
  trait A;
  case class B() extends A;
  def f(x: A): B = x match { case B() => x };
}
what happened
caseTest.scala:4: type mismatch;
 found   : caseTest.A
 required: caseTest.B
  def f(x: A): B = x match { case B() => x };
                                         ^
what expected The typechecker could be able to realize that x is a B since it complies to the pattern "B()".
[back to overview]
Changes of this bug report
Burak  edited on  2003-11-04 17:36:56.0

(wrapped the "what happened" in a pre tag).

I was annoyed myself that pico does not "automatically cast x". However consider that you can get the same by writing

def f(x: A): B = x match { case y @ B() => y };

I am not sure what happens if you give an Ident referencing this symbol a better type.

What is clear is that since the match could be followed by other statements in the block, you cannot replace the references to x by references to another symbol.

Martin  edited on  2003-11-07 12:53:26.0
Since `x' may be an arbitrary expression, I think it's too hard to specify and implement the desrived behavior.