From 8716fac3e392e2968df4f681474b2ee2964c834f Mon Sep 17 00:00:00 2001 From: Dmitry Petrashko Date: Mon, 13 Mar 2017 14:12:01 +0100 Subject: Fix #2084. --- .../src/dotty/tools/dotc/transform/TypeTestsCasts.scala | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'compiler/src/dotty/tools/dotc/transform/TypeTestsCasts.scala') diff --git a/compiler/src/dotty/tools/dotc/transform/TypeTestsCasts.scala b/compiler/src/dotty/tools/dotc/transform/TypeTestsCasts.scala index 3774127fa..a2119bfe4 100644 --- a/compiler/src/dotty/tools/dotc/transform/TypeTestsCasts.scala +++ b/compiler/src/dotty/tools/dotc/transform/TypeTestsCasts.scala @@ -96,23 +96,30 @@ trait TypeTestsCasts { /** Transform isInstanceOf OrType * * expr.isInstanceOf[A | B] ~~> expr.isInstanceOf[A] | expr.isInstanceOf[B] + * expr.isInstanceOf[A & B] ~~> expr.isInstanceOf[A] & expr.isInstanceOf[B] * * The transform happens before erasure of `argType`, thus cannot be merged * with `transformIsInstanceOf`, which depends on erased type of `argType`. */ - def transformOrTypeTest(qual: Tree, argType: Type): Tree = argType.dealias match { + def transformTypeTest(qual: Tree, argType: Type): Tree = argType.dealias match { case OrType(tp1, tp2) => evalOnce(qual) { fun => - transformOrTypeTest(fun, tp1) - .select(nme.OR) - .appliedTo(transformOrTypeTest(fun, tp2)) + transformTypeTest(fun, tp1) + .select(defn.Boolean_||) + .appliedTo(transformTypeTest(fun, tp2)) + } + case AndType(tp1, tp2) => + evalOnce(qual) { fun => + transformTypeTest(fun, tp1) + .select(defn.Boolean_&&) + .appliedTo(transformTypeTest(fun, tp2)) } case _ => transformIsInstanceOf(qual, erasure(argType)) } if (sym eq defn.Any_isInstanceOf) - transformOrTypeTest(qual, tree.args.head.tpe) + transformTypeTest(qual, tree.args.head.tpe) else if (sym eq defn.Any_asInstanceOf) transformAsInstanceOf(erasure(tree.args.head.tpe)) else tree -- cgit v1.2.3