Aladdin - Scala Bugtracking
[#230] project: compiler priority: medium category: bug
submitter assigned to status date submitted
Stephane Matthias fixed 2003-11-19 14:58:04.0
subject Problem in for construct
code
object Test with Executable {
  for (val i: Int <- Iterator.range(1, 2)) {
    Console.println(i);
  }
}
what happened
Test.scala:3: unreachable code
  for (val i: Int <- Iterator.range(1, 2)) {
                                         ^
one error found
what expected index value is printed out !
[back to overview]
Changes of this bug report
Martin  edited on  2003-11-19 16:29:02.0
Matthias  edited on  2003-11-20 11:38:25.0
This must be a bug in the analyzer which generates two default cases in a pattern matching construct. I'm not even sure why pattern matching is involved at all... Here's the code after the Analyzer phase:
final object Test extends scala.Object() with scala.Executable() {
  scala.Iterator.range(1, 2).filter({
      class $anon() extends scala.Object() with scala.Function1[scala.Int, scala.Boolean]() {
        final def apply(ds$0: scala.Int): scala.Boolean = ds$0.match({
            case i @ (_) : scala.Int => true
            case _ => false
          })
      };
      new $anon()
    }).foreach({
      class $anon() extends scala.Object() with scala.Function1[scala.Int, scala.Unit]() {
        final def apply(ds$1: scala.Int): scala.Unit = ds$1.match({
            case i @ (_) : scala.Int => scala.Console.println(i)
          })
      };
      new $anon()
    })
}
Matthias  edited on  2003-11-20 12:06:22.0
Okay, I just checked the spec. It seems like there are no restrictions on case sequences, which consequently means for my checks that they are too strict. To comply with the spec I allow for now to have duplicate cases (also multiple default cases). But overall I think the spec of pattern matching expressions doesn't fit to Scala! Scala is, in the terminology of Smalltalk/Lisp programmers, a pesimistic language, forbiding programs which are totally fine but where the type system cannot exclude errors. For pattern matching the Scala spec is pretty optimistic, allowing pattern combinations where it would be perfectly feasible to statically prove their redundancy.
Matthias  edited on  2003-11-20 12:07:02.0
Okay, I just checked the spec. It seems like there are no restrictions on case sequences, which consequently means for my checks that they are too strict. To comply with the spec I allow for now to have duplicate cases (also multiple default cases). But overall I think the spec of pattern matching expressions doesn't fit to Scala! Scala is, in the terminology of Smalltalk/Lisp programmers, a pesimistic language, forbiding programs which are totally fine but where the type system cannot exclude errors. For pattern matching the Scala spec is pretty optimistic, allowing pattern combinations where it would be perfectly feasible to statically prove their redundancy.