scala/scala — pull request #2053 by retronym (2013-02-02 10:22:46+00:00)
Title: SI-6146 More accurate prefixes for sealed subtypes.

When analysing exhaustivity/reachability of type tests
and equality tests, the pattern matcher must construct
a set of sealed subtypes based on the prefix of the
static type of and the set of sealed descendent symbols
of that type.

Previously, it was using `memberType` for this purpose.
In simple cases, this is sufficient:

scala> class C { class Inner }; object D extends C
defined class C
defined module D

scala> typeOf[D.type] memberType typeOf[C#Inner].typeSymbol
res0: u.Type = D.Inner

But, as reported in this bug, it fails when there is an
additional level of nesting:

scala> typeOf[D.type] memberType typeOf[c.O.Inner forSome { val c: C }].typeSymbol
res5: u.Type = C.O.Inner

scala> typeOf[Any] memberType typeOf[c.O.Inner forSome { val c: C }].typeSymbol
res6: u.Type = C.O.Inner

This commit introduces `deepMemberType`, which uses `memberType`
recursively over the prefix chain.

scala> deepMemberType(typeOf[D.type], typeOf[c.O.Inner forSome { val c: C }].typeSymbol)
res3: u.Type = D.O.Inner

Review by @adriaanm && @paulp
- I'm not sure how to join the dots on the connection to `dealiasWiden`
- `memberTypeDeep` is something of a straw-man, better suggestions?
- is this something we might expect `AsSeenFrom` to handle automatically?