diff options
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) |