| [#1159] | project: compiler | priority: low | category: bug | |
|---|---|---|---|---|
| submitter | assigned to | status | date submitted | |
| Martin | Burak | moved to trac | 2007-05-31 16:15:34.0 | |
| subject | pattern matching does not wlways check outer | |||
| code |
class Outer {
case class Foo(x: int, y: int) {
override def equals(other: Any) = other match {
case Outer.this.Foo(`x`, `y`) => true
case _ => false
}
}
}
object Test extends Application {
val o1 = new Outer
val o2 = new Outer
val x: Any = o1.Foo(1, 2)
val y: Any = o2.Foo(1, 2)
println(x equals y)
x match {
case o2.Foo(x, y) => println("error 1")
case o1.Foo(x, y) => println("OK")
case _ => println("error 2")
}
}
|
|||
| what happened | true OK |
|||
| what expected | false OKThe example shows that outers are tested in the second match, but not in the first one (i.e. in the equality method of class Foo). |
|||
| [back to overview] | ||||
| Martin edited on 2007-05-31 16:19:52.0 |
| When fixing this, it's tricky not too insert too many outer tests. For instance, if `other' in `equals' had type `Outer.this.Foo' instead of `Any', there should be no outer test, because we know statically that the outer pointers must be the same (if not, the types would not work out). |
| Gilles edited on 2007-08-29 09:52:52.0 |