Aladdin - Scala Bugtracking
[#1222] project: compiler priority: medium category: bug
submitter assigned to status date submitted
Philipp Burak fixed 2007-07-18 12:25:45.0
subject Guard in pattern with unapply crashes compiler
code
object guardCrash2 extends Application {

  class &(left: Any, right: Any)

  object & {
    def apply(left: Any, right: Any) = new &(left, right)
    def unapply(scrut: Any): Option[(Any, Any)] = Some((scrut, scrut))
  }

  class Sync {
    def unapply(scrut: Any): Boolean = true
  }

  class Buffer {
    case class Put(x: int)
    object Get extends Sync

    def pattern(x: Any) = x match {
      // guard `if y > 4' crashes compiler
      case Get() & Put(y) if y > 4 => y
    }
  }
}
what happened
exception when transforming def pattern(x: Any): Int = x match {
  case guardCrash2.this.&.unapply()  (Buffer.this.Get().unapply() <\
unapply> (), (Int)Buffer.this.Put((y @ _))) if y.>(4) => y
}
...
Exception in thread "main" java.lang.AssertionError: assertion failed
        at scala.Predef$.assert(Predef.scala:85)
        at scala.tools.nsc.matching.PatternMatchers$PatternMatcher.enter1(PatternMatchers.scala:608)
        at scala.tools.nsc.matching.PatternMatchers$PatternMatcher.enter(PatternMatchers.scala:698)
        at scala.tools.nsc.matching.PatternMatchers$PatternMatcher.enter1(PatternMatchers.scala:665)
        at scala.tools.nsc.matching.PatternMatchers$PatternMatcher.enter(PatternMatchers.scala:296)
        at scala.tools.nsc.matching.PatternMatchers$PatternMatcher$$anonfun$4.apply(PatternMatchers.scala:211)
        at scala.tools.nsc.matching.PatternMatchers$PatternMatcher$$anonfun$4.apply(PatternMatchers.scala:211)
        at scala.List.foreach(List.scala:707)
        at scala.tools.nsc.matching.PatternMatchers$PatternMatcher.constructIncremental(PatternMatchers.scala:21\
1)
        at scala.tools.nsc.matching.PatternMatchers$PatternMatcher.construct(PatternMatchers.scala:157)
        at scala.tools.nsc.matching.TransMatcher$class.handlePattern(TransMatcher.scala:298)
        at scala.tools.nsc.transform.ExplicitOuter.handlePattern(ExplicitOuter.scala:19)
        at scala.tools.nsc.transform.ExplicitOuter$ExplicitOuterTransformer.transform(ExplicitOuter.scala:433)
...
what expected Should compile without error.
[back to overview]
Changes of this bug report
Burak  edited on  2007-08-08 11:28:33.0
this must have got fixed along the way.