Aladdin - Scala Bugtracking
[#33] project: compiler priority: medium category: feature
submitter assigned to status date submitted
Stephane Martin won't fix 2003-07-01 18:58:03.0
subject expected pattern does not conform
code
object Main {

    type Data = Any;

    def foo(x: Data): String = x match {
        case Nil => ""
        case (head :: List(ys)) :: zs =>
            val body = ys match {
//              case Nil => ""
               case List() => ""
                case _ => " :- " + ys.toString()
            };
            head.toString() + body + ".\n"
                + foo(zs)
    }

    def main(args: Array[String]) = {
    	val xs = (3 :: List(4)) :: Nil;
        System.out.println(foo(xs));
    }

}
what happened
Main.scala:11: expected pattern type scala.Any does not conform to sequence trait scala.List
               case List() => ""
                    ^
Main.scala:11: trait scala.List of type scala.List[a] cannot be applied to () with expected result type scala.An\
y
               case List() => ""
                        ^
two errors found
what expected 3 :- 4 is printed out !
[back to overview]
Changes of this bug report
Martin  edited on  2003-07-01 19:00:00.0
That's actually the specified behaviour. A selector of type Any cannot be matched against List(), since Any is not a sequence type. It can only be matched against case classes, and List is not a case class.