diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2013-01-31 00:33:19 +0100 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2013-02-07 21:58:47 +0100 |
commit | 55c9b9c280ac9bc36bbac09397c7646f8dcf4583 (patch) | |
tree | cdfc1cd396eaba78f0150968634722bcb8df8bd7 /test/files/pos/t6146.scala | |
parent | 81d8f9d3da656cfb05f125ba7cf70ca51a477240 (diff) | |
download | scala-55c9b9c280ac9bc36bbac09397c7646f8dcf4583.tar.gz scala-55c9b9c280ac9bc36bbac09397c7646f8dcf4583.tar.bz2 scala-55c9b9c280ac9bc36bbac09397c7646f8dcf4583.zip |
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 I1; object O { class I2 } }; object D extends C
defined class C
defined module D
scala> typeOf[D.type] memberType typeOf[C#I1].typeSymbol
res0: u.Type = D.I1
But, as reported in this bug, it fails when there is an
additional level of nesting:
scala> typeOf[D.type] memberType typeOf[c.O.I2 forSome { val c: C }].typeSymbol
res5: u.Type = C.O.I2
This commit introduces `nestedMemberType`, which uses `memberType`
recursively up the prefix chain prefix chain.
scala> nestedMemberType(typeOf[c.O.I2 forSome { val c: C }].typeSymbol, typeOf[D.type], typeOf[C].typeSymbol)
res6: u.Type = D.O.Id
Diffstat (limited to 'test/files/pos/t6146.scala')
-rw-r--r-- | test/files/pos/t6146.scala | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/test/files/pos/t6146.scala b/test/files/pos/t6146.scala new file mode 100644 index 0000000000..b5bde826b1 --- /dev/null +++ b/test/files/pos/t6146.scala @@ -0,0 +1,60 @@ +// No unreachable or exhaustiveness warnings, please. + +// +// The reported bug +// + +trait AxisCompanion { + sealed trait Format + object Format { + case object Decimal extends Format + case object Integer extends Format + // Gives an unrelated warning: The outer reference in this type test cannot be checked at run time. + //final case class Time( hours: Boolean = false, millis: Boolean = true ) extends Format + } +} +object Axis extends AxisCompanion +class Axis { + import Axis._ + def test( f: Format ) = f match { + case Format.Integer => "Int" + // case Format.Time( hours, millis ) => "Time" + case Format.Decimal => "Dec" + } +} + + +// +// Some tricksier variations +// + +trait T1[X] { + trait T2[Y] { + sealed trait Format + object Format { + case object Decimal extends Format + case object Integer extends Format + } + } +} + +object O1 extends T1[Any] { + object O2 extends T2[Any] { + + } +} + +case object Shorty extends O1.O2.Format + +class Test1 { + import O1.O2._ + val FI: Format.Integer.type = Format.Integer + def test( f: Format ) = { + val ff: f.type = f + ff match { + case FI => "Int" + case Format.Decimal => "Dec" + case Shorty => "Sho" + } + } +} |