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/ast/Desugar.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/ast/Desugar.scala')
-rw-r--r-- | src/dotty/tools/dotc/ast/Desugar.scala | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/dotty/tools/dotc/ast/Desugar.scala b/src/dotty/tools/dotc/ast/Desugar.scala index 8a4b9cfe8..346af42b8 100644 --- a/src/dotty/tools/dotc/ast/Desugar.scala +++ b/src/dotty/tools/dotc/ast/Desugar.scala @@ -616,16 +616,20 @@ object desugar { * * { cases } * ==> - * x$1 => x$1 match { cases } + * x$1 => (x$1 @unchecked) match { cases } * * If `nparams` != 1, expand instead to * - * (x$1, ..., x$n) => (x$0, ..., x${n-1}) match { cases } + * (x$1, ..., x$n) => (x$0, ..., x${n-1} @unchecked) match { cases } */ - def makeCaseLambda(cases: List[CaseDef], nparams: Int = 1)(implicit ctx: Context) = { + def makeCaseLambda(cases: List[CaseDef], nparams: Int = 1, unchecked: Boolean = true)(implicit ctx: Context) = { val params = (1 to nparams).toList.map(makeSyntheticParameter(_)) val selector = makeTuple(params.map(p => Ident(p.name))) - Function(params, Match(selector, cases)) + + if (unchecked) + Function(params, Match(Annotated(New(ref(defn.UncheckedAnnotType)), selector), cases)) + else + Function(params, Match(selector, cases)) } /** Map n-ary function `(p1, ..., pn) => body` where n != 1 to unary function as follows: @@ -753,7 +757,7 @@ object desugar { case VarPattern(named, tpt) => Function(derivedValDef(named, tpt, EmptyTree, Modifiers(Param)) :: Nil, body) case _ => - makeCaseLambda(CaseDef(pat, EmptyTree, body) :: Nil) + makeCaseLambda(CaseDef(pat, EmptyTree, body) :: Nil, unchecked = false) } /** If `pat` is not an Identifier, a Typed(Ident, _), or a Bind, wrap @@ -799,7 +803,7 @@ object desugar { val cases = List( CaseDef(pat, EmptyTree, Literal(Constant(true))), CaseDef(Ident(nme.WILDCARD), EmptyTree, Literal(Constant(false)))) - Apply(Select(rhs, nme.withFilter), Match(EmptyTree, cases)) + Apply(Select(rhs, nme.withFilter), makeCaseLambda(cases)) } /** Is pattern `pat` irrefutable when matched against `rhs`? |