diff options
author | liu fengyun <liufengyunchina@gmail.com> | 2016-07-21 10:41:59 +0200 |
---|---|---|
committer | liu fengyun <liufengyunchina@gmail.com> | 2016-08-24 10:26:58 +0200 |
commit | 1a7618f32c6d8060c3a87ce633645440d500aa7a (patch) | |
tree | c61d576426280d36417e64198716c71aa9e0b6ca /src/dotty/tools/dotc/transform/PatternMatcher.scala | |
parent | 265ade02e522c89844076b5339267eac08e44c37 (diff) | |
download | dotty-1a7618f32c6d8060c3a87ce633645440d500aa7a.tar.gz dotty-1a7618f32c6d8060c3a87ce633645440d500aa7a.tar.bz2 dotty-1a7618f32c6d8060c3a87ce633645440d500aa7a.zip |
implementation of exhaustivity and redundancy check
Diffstat (limited to 'src/dotty/tools/dotc/transform/PatternMatcher.scala')
-rw-r--r-- | src/dotty/tools/dotc/transform/PatternMatcher.scala | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/src/dotty/tools/dotc/transform/PatternMatcher.scala b/src/dotty/tools/dotc/transform/PatternMatcher.scala index 839189948..21b56959b 100644 --- a/src/dotty/tools/dotc/transform/PatternMatcher.scala +++ b/src/dotty/tools/dotc/transform/PatternMatcher.scala @@ -24,6 +24,7 @@ import Applications._ import TypeApplications._ import SymUtils._, core.NameOps._ import core.Mode +import patmat._ import dotty.tools.dotc.util.Positions.Position import dotty.tools.dotc.core.Decorators._ @@ -52,6 +53,13 @@ class PatternMatcher extends MiniPhaseTransform with DenotTransformer {thisTrans override def transformMatch(tree: Match)(implicit ctx: Context, info: TransformerInfo): Tree = { val translated = new Translator()(ctx).translator.translateMatch(tree) + // check exhaustivity and unreachability + val engine = new SpaceEngine + if (engine.checkable(tree)) { + engine.checkExhaustivity(tree) + engine.checkRedundancy(tree) + } + translated.ensureConforms(tree.tpe) } @@ -1244,13 +1252,6 @@ class PatternMatcher extends MiniPhaseTransform with DenotTransformer {thisTrans case _ => false } - def elimAnonymousClass(t: Type) = t match { - case t:TypeRef if t.symbol.isAnonymousClass => - t.symbol.asClass.typeRef.asSeenFrom(t.prefix, t.symbol.owner) - case _ => - t - } - /** Implement a pattern match by turning its cases (including the implicit failure case) * into the corresponding (monadic) extractors, and combining them with the `orElse` combinator. * @@ -1264,7 +1265,7 @@ class PatternMatcher extends MiniPhaseTransform with DenotTransformer {thisTrans def translateMatch(match_ : Match): Tree = { val Match(sel, cases) = match_ - val selectorTp = elimAnonymousClass(sel.tpe.widen/*withoutAnnotations*/) + val selectorTp = sel.tpe.widen.deAnonymize/*withoutAnnotations*/ val selectorSym = freshSym(sel.pos, selectorTp, "selector") @@ -1273,6 +1274,7 @@ class PatternMatcher extends MiniPhaseTransform with DenotTransformer {thisTrans case _ => (cases, None) } + // checkMatchVariablePatterns(nonSyntheticCases) // only used for warnings // we don't transform after uncurry |