diff options
author | Iulian Dragos <jaguarul@gmail.com> | 2010-02-28 21:09:06 +0000 |
---|---|---|
committer | Iulian Dragos <jaguarul@gmail.com> | 2010-02-28 21:09:06 +0000 |
commit | b94c6e0da6d33bc69f1419634128e2f401109b61 (patch) | |
tree | 89d1ed33a06fa92ae1282034927b188d4cf9398c /src | |
parent | 9bfc0f0ac615b48b39b696dc1fb61ba07e5e8274 (diff) | |
download | scala-b94c6e0da6d33bc69f1419634128e2f401109b61.tar.gz scala-b94c6e0da6d33bc69f1419634128e2f401109b61.tar.bz2 scala-b94c6e0da6d33bc69f1419634128e2f401109b61.zip |
Fixed specialized pattern matches.
specialized implementations.
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Duplicators.scala | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Duplicators.scala b/src/compiler/scala/tools/nsc/typechecker/Duplicators.scala index 40cf9e82c0..7ca2ff81bb 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Duplicators.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Duplicators.scala @@ -240,9 +240,28 @@ abstract class Duplicators extends Analyzer { log("changed " + tree + " to " + tree1) super.typed(atPos(tree.pos)(tree1)) + case Match(scrut, cases) => + val scrut1 = typed(scrut, EXPRmode | BYVALmode, WildcardType) + val scrutTpe = scrut1.tpe.widen + val cases1 = if (scrutTpe.isFinalType) cases filter { + case CaseDef(Bind(_, pat @ Typed(_, tpt)), EmptyTree, body) => + // the typed pattern is not incompatible with the scrutinee type + scrutTpe.matchesPattern(fixType(tpt.tpe)) + case CaseDef(Typed(_, tpt), EmptyTree, body) => + // the typed pattern is not incompatible with the scrutinee type + scrutTpe.matchesPattern(fixType(tpt.tpe)) + case _ => true + } else cases + + super.typed(atPos(tree.pos)(Match(scrut, cases1)), mode, pt) + + case EmptyTree => + // no need to do anything, in particular, don't set the type to null, EmptyTree.tpe_= asserts + tree + case _ => if (tree.hasSymbol && tree.symbol != NoSymbol && (tree.symbol.owner == definitions.AnyClass)) { - tree.symbol = NoSymbol // maybe we can find a more specific member in a subclass of Any + tree.symbol = NoSymbol // maybe we can find a more specific member in a subclass of Any (see AnyVal members, like ==) } tree.tpe = null super.typed(tree, mode, pt) |