I'm running into a strange issue involving pattern matching and an
extractor object.
object SymbolMatcher {
def unapply(tree: Tree): Option[String] = tree match {
case Apply(_, StringLit(s)::Nil) if tree.symbol == symbolApplyMethod =>
Some(s)
case _ =>
None
}
}
}
...
arg match {
case Apply(_, List(SymbolMatcher(label), arg)) =>
(Some(label), getType(arg))
//case Apply(_,StringLit(label)::Nil) if arg.symbol == symbolApplyMethod =>
case SymbolMatcher(label) =>
println("normal")
(Some(label), None)
case arg => arg match {
case SymbolMatcher(label) =>
println("strange...")
(Some(label), None)
case x =>
(None, getType(arg))
}
}
The pattern goes into the "strange..." branch. However, if I use the
commented out line instead of case SymbolMatcher(label), the pattern
goes into the "normal" branch.
Am I right to think that this isn't normal?
Olivier
On 2/11/11 11:06 AM, Olivier Pernet wrote:
> I'm running into a strange issue involving pattern matching and an
> extractor object.
I'm sure it's the famous (for some of us) 1697/2337.
http://lampsvn.epfl.ch/trac/scala/ticket/1697
"Compiler generates wrong code from some code using extractor"
https://lampsvn.epfl.ch/trac/scala/ticket/2337
"Transition from pattern match based on extractor with a typed parameter
in unapply() skips next case"
> Am I right to think that this isn't normal?
Unfortunately it depends on how we define normalcy.
What do you mean "we"? You already know most of us know better by now and will just defer to your definition! :)
(eventually, anyway...)
Right, this does look a lot like my problem.
Do you have an idea of what's going on there?
Olivier
Here, this will get you started.
http://permalink.gmane.org/gmane.comp.lang.scala.internals/2752
There is little doubt in my mind at this point that this bug will be
gone after I rewrite the matcher and not before, because we're years
into this now and there's still no sign of anyone who can help me with
the pattern matcher. So it has to be me, and I'm done working it from
the inside.
Do you think I would be safe from the bug if I wrote all my extractors
to take Any as a parameter and do the type check inside the extractor?
Olivier
I have started it. It's the kind of thing I will need to focus on for a
while though, and I'm not sure when that's going to be a viable thing
for me to do.
> Do you think I would be safe from the bug if I wrote all my extractors
> to take Any as a parameter and do the type check inside the extractor?
I am fairly sure that leaves you safe from this bug. This does not
imply there aren't others.
Do you have anything online about it? I'd like to help, but I'd need
to learn a lot first I'm sure...
>> Do you think I would be safe from the bug if I wrote all my extractors
>> to take Any as a parameter and do the type check inside the extractor?
>
> I am fairly sure that leaves you safe from this bug. This does not imply
> there aren't others.
Actually, I just tried, and the bug was still there.
Olivier
I'd like to put a lot of my work in progress online one of these days,
but it isn't yet. Hang onto that interest.