diff options
author | Grzegorz Kossakowski <grzegorz.kossakowski@gmail.com> | 2012-01-25 18:42:52 +0100 |
---|---|---|
committer | Grzegorz Kossakowski <grzegorz.kossakowski@gmail.com> | 2012-02-01 17:20:04 +0100 |
commit | aa7759651d25ab8c315a2d36e3f28cf3caaa041f (patch) | |
tree | feffa9f170a4050fa49edb1b948fafd654911b38 /src | |
parent | 97912733f9e7e2c2528ebbab6b70ef35b8dd0fbc (diff) | |
download | scala-aa7759651d25ab8c315a2d36e3f28cf3caaa041f.tar.gz scala-aa7759651d25ab8c315a2d36e3f28cf3caaa041f.tar.bz2 scala-aa7759651d25ab8c315a2d36e3f28cf3caaa041f.zip |
Generate default case for switches.
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/PatMatVirtualiser.scala | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/PatMatVirtualiser.scala b/src/compiler/scala/tools/nsc/typechecker/PatMatVirtualiser.scala index 0b35f1b1d0..cf5985eeee 100644 --- a/src/compiler/scala/tools/nsc/typechecker/PatMatVirtualiser.scala +++ b/src/compiler/scala/tools/nsc/typechecker/PatMatVirtualiser.scala @@ -1160,9 +1160,20 @@ defined class Foo */ sequence(caseDefs) map { caseDefs => import CODE._ + val caseDefsWithDefault = { + def isDefault(x: CaseDef): Boolean = x match { + case CaseDef(Ident(nme.WILDCARD), EmptyTree, _) => true + case _ => false + } + val hasDefault = caseDefs exists isDefault + if (hasDefault) caseDefs else { + val default = atPos(scrut.pos) { DEFAULT ==> MATCHERROR(REF(scrutSym)) } + caseDefs :+ default + } + } val matcher = BLOCK( VAL(scrutSym) === scrut, // TODO: type test for switchable type if patterns allow switch but the scrutinee doesn't - Match(REF(scrutSym), caseDefs) // match on scrutSym, not scrut to avoid duplicating scrut + Match(REF(scrutSym), caseDefsWithDefault) // match on scrutSym, not scrut to avoid duplicating scrut ) // matcher filter (tree => tree.tpe == null) foreach println |