I think it's because typeTest in ' static' mode emits the test that ensures that the static type of scrutinee conforms to a case. I was also puzzled by that, when tried to implement tag-aware matching for abstract types.
A pattern binder x@p consists of a pattern variable x and a pattern p. The type of the variable x is the static type T of the pattern p.
All alternative patterns are type checked with the expected type of the pattern.
No idea, we did not have time to discuss this with Adriaan
On May 16, 2012 4:05 PM, "√iktor Ҡlang" <viktor...@gmail.com> wrote:
Is it a bug, and if so, is there a ticket for it already?
On Wed, May 16, 2012 at 3:01 PM, Eugene Burmako <eugene....@epfl.ch> wrote:
>
> I think it's b...
Does this mean that I cannot match something of static type Tree against, say, Apply?
On Wed, May 16, 2012 at 2:20 PM, Adriaan Moors <adriaa...@epfl.ch> wrote:But surely the LUB here should be Exception not Throwable?
> I think we're talking about different things here.
>
> recall Viktor's example:
> (new IllegalStateException).asInstanceOf[Throwable] match { case e @ (_:
> IllegalStateException | _: ClassCastException) => val sanity: Exception = e
> }
>
> `e` has type `Throwable` since that's how alternatives are type checked,
> thus you can't assign it to sanity
I'm not sure I see how Viktor's example is different from,
scala> class A ; class B extends A ; class C extends A
defined class A
defined class B
defined class C
scala> ((new B) : A) match { case a @ (_ : B | _ : C) => val sanity : A = a }
On Wed, May 16, 2012 at 2:30 PM, martin odersky <martin....@epfl.ch> wrote:Fair enough, but it seems a little unfortunate that,
> No, there is no LUB computed. We can't because types in patterns flow from
> the root (selector type) to the leaves (variables in patterns),
(new IllegalStateException).asInstanceOf[Throwable] match {
case e : IllegalStateException => val sanity: Exception = e
case e : ClassCastException => val sanity : Exception = e
}
which you might naively think is equivalent to Viktor's eg. is
perfectly OK, especially since one of the main uses of pattern
alternatives is to eliminate duplicate case clause RHS's in precisely
this kind of situation.
Cheers,
Miles
--
Miles Sabin
tel: +44 7813 944 528
gtalk: mi...@milessabin.com
skype: milessabin
g+: http://www.milessabin.com
http://twitter.com/milessabin
http://underscoreconsulting.com
http://www.chuusai.com