[#451] | project: compiler | priority: medium | category: bug | |
---|---|---|---|---|
submitter | assigned to | status | date submitted | |
Iulian | Burak | noise | 2005-07-13 15:40:11.0 | |
subject | Parser does not accept "this" as value inside patterns | |||
code |
class A { def matchme(t: Tree) = { val b = this; t match { case DefDef(b) => Console.println("Ok!"); // case DocDef(this) => Console.println("Ok!"); case _ => Console.println("not ok"); } } } trait Tree; case class DefDef(a: A) extends Tree; case class DocDef(b: A) extends Tree; |
|||
what happened | If I uncomment the second pattern, I get this:this-match.scala:7: '.' expected but ')' found. case DocDef(this) => Console.println("Ok!"); ^ |
|||
what expected | No compiler error. The first pattern shows that it works fine with normal values, why should this be treated differently? |
|||
[back to overview] |
Iulian edited on 2005-07-13 15:40:42.0 |
Added tags |
Iulian edited on 2005-07-13 15:51:46.0 |
No bug, my example doesn't work. As Michel explained, the "b" inside the pattern is a new variable which shadows the previous definition. "b" gets the value of whatever is inside DefDef, even if that's not equal to `this'. |
Burak edited on 2005-07-13 16:57:45.0 |
In the pattern, try to write "A.this" instead of "this"! |