Aladdin - Scala Bugtracking
[#149] project: compiler priority: medium category: bug
submitter assigned to status date submitted
Martin Matthias fixed 2003-09-24 18:24:27.0
subject Pattern matcher assigns wrong types
code
object Test {
  def flatten[a](l: List[List[a]]): List[a] = l match {
    case Nil => Nil
    case head :: tail => head ::: flatten(tail)
  }
}
what happened
If you compile with scalac -print:transmatch -types, you get the following output:
[[Trees after phase transmatch]]
// Scala source: test/pos/pmbug.scala
final class Test() extends scala{scala.type}.Object{()scala.Object}(){scala.Object} {
  final def flatten[a](l: scala.List[scala.List[a]]): scala.List[a] = {
    val temp$0: l.type = l{l.type};
    var $result$0: scala.List[a] = null{null.type};
    if (if (temp$0{scala.List[scala.List[a]]}.$eq$eq{(scala.Any)scala.Boolean}(scala{scala.type}.Nil{scala.Nil})\
{scala.Boolean})
      {
        $result$0{scala.List[a]} = scala{scala.type}.Nil{scala.Nil};
        true{scala.Boolean}
      }{scala.Boolean}
    else
       if (temp$0{scala.List[scala.List[a]]}.isInstanceOf{[T]()scala.Boolean}[scala.::[scala.List[a]]]{()scala.B\
oolean}(){scala.Boolean})
        {
          val temp$1: scala.::[scala.List[a]] = temp$0{scala.List[scala.List[a]]}.asInstanceOf{[T]()T}[scala.::[\
scala.List[a]]]{()scala.::[scala.List[a]]}(){scala.::[scala.List[a]]};
          val head: scala.List[a] = temp$1{scala.::[scala.List[a]]}.hd{()b}(){scala.List[a]};
          val tail: scala.List[scala.List[a]] = temp$1{scala.::[scala.List[a]]}.tl{()scala.List[b]}(){scala.List\
[scala.List[a]]};
          $result$0{scala.List[a]} = {
            val x$0: scala.List[a] = head{scala.List[a]};
            Test{Test.type}.flatten{[a](scala.List[scala.List[a]])scala.List[a]}[a]{(scala.List[scala.List[a]])s\
cala.List[a]}(tail{scala.List[scala.List[a]]}){scala.List[a]}.$colon$colon$colon{[b >: a](scala.List[b])scala.Li\
st[b]}[a]{(scala.List[a])scala.List[a]}(x$0{scala.List[a]}){scala.List[a]}
          }{scala.List[a]};
          true{scala.Boolean}
        }{scala.Boolean}
      else
         false{scala.Boolean}{scala.Boolean}{scala.Boolean})
      $result$0{scala.List[a]}
    else
       scala{scala}.MatchError{scala.MatchError}.fail{[?T](java.lang.String,scala.Int)?T}[scala.List[a]]{(java.l\
ang.String,scala.Int)scala.List[a]}("test/pos/pmbug.scala"{scala.String}, 3{scala.Int}){scala.List[a]}{scala.Lis\
t[a]}
  }{scala.List[a]}
};
final /*object*/ val Test: Test = new Test{()Test}(){Test}{Test};
The problem lies in the following line:
  val head: scala.List[a] =
    temp$1{scala.::[scala.List[a]]}.hd{()b}(){scala.List[a]};
Here, temp$1.hd has type ()b, where it should be ()a. This bug is blocking a fix for bug115.
what expected Type of temp$1.hd has type ()b should be ()a.
[back to overview]
Changes of this bug report
Matthias  edited on  2003-09-24 23:08:38.0