Aladdin - Scala Bugtracking
[#457] project: nsc priority: high category: bug
submitter assigned to status date submitted
Iulian Martin fixed 2005-10-11 17:23:32.0
subject [nsc] Wrong behavior of Erasure for pattern guards (which contain pattern matches)
code
<code>
object Foo {

//   def method= {
//     val x = "Hello, world";
//     val y = 100;
    
//      y match {
//        case _: Int 
//         if (x match { case t => t.trim().length() == 0 }) =>
//           false;
// //      case _ => true;
//     }
//   }

  def method2(): scala.Boolean = {
    val x: java.lang.String = "Hello, world";
    val y: scala.Int = 100;
    {
      var temp1: scala.Int = y;
      var result: scala.Boolean = false;
      if (
        {
          var result1: scala.Boolean = false;
          if (y == 100)
            result1
          else
            scala.MatchError.fail("crazybox.scala", 11)
        } && (y == 90)
      )
        result
      else
        scala.MatchError.fail("crazybox.scala", 9);
    }
  }

}
</code>
what happened
The commented part is the 'source' of the error, and in method2 I tried to trim as much output from the transmat\
ch as possible, while still having the wrong behavior.

Here is the output after erasure:

        if ({
          var result1: scala.Boolean! = false;
          if (y.==(100))
            result1
          else
            scala.MatchError.fail("crazybox.scala", 11)
        }.$asInstanceOf[scala.runtime.BoxedBoolean!]().booleanValue().&&(y.==(90)))
          result
        else
          scala.MatchError.fail("crazybox.scala", 9).$asInstanceOf[scala.runtime.BoxedBoolean!]().booleanValue()\

      }
The interesting part is the casting to BoxedBoolean in the innermost if. That should apply to the call to MatchE\ rror.fail, like in the outermost case. Or otherwise, the 'then' branch should return a BoxedBoolean instead of j\ ust a Boolean (result1 is a plain Boolean).
what expected See above.
[back to overview]
Changes of this bug report
Iulian  edited on  2005-10-18 13:42:48.0
Iulian  edited on  2005-11-09 12:09:55.0