Aladdin - Scala Bugtracking
[#401] project: compiler priority: medium category: bug
submitter assigned to status date submitted
Burak Martin fixed 2005-02-21 15:46:43.0
subject typing of patterns
code
object BugSequenceApply with Application {

  val x = List(1,2,3);

  case class ThreeBars extends Seq[Int] {
    override def length = 3;
    def elements = x.elements;
    def apply(i:Int) = x.apply(i);
  }

  Console.println(ThreeBars().match { //pattern has type ThreeBars,
    case Seq(1,2,3) => "hello" // but ThreeBars is a case class...
  });
}
what happened
Pattern matcher crashes, because it thinks that it needs to handle a case class with a star parameter. This is b\
ecause the pattern Seq(1,2,3) gets assigned the type ThreeBars
what expected Assigning the greater type Seq to the pattern would resolve this problem. Note that the (topdown/nonregular) pattern matcher already keeps track of expected types by itself.
[back to overview]
Changes of this bug report
Martin  edited on  2006-06-29 00:23:22.0