Skip to content

Commit 8716fac

Browse files
DarkDimiusfelixmulder
authored andcommitted
Fix #2084.
1 parent aedd4e0 commit 8716fac

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

compiler/src/dotty/tools/dotc/transform/TypeTestsCasts.scala

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,23 +96,30 @@ trait TypeTestsCasts {
9696
/** Transform isInstanceOf OrType
9797
*
9898
* expr.isInstanceOf[A | B] ~~> expr.isInstanceOf[A] | expr.isInstanceOf[B]
99+
* expr.isInstanceOf[A & B] ~~> expr.isInstanceOf[A] & expr.isInstanceOf[B]
99100
*
100101
* The transform happens before erasure of `argType`, thus cannot be merged
101102
* with `transformIsInstanceOf`, which depends on erased type of `argType`.
102103
*/
103-
def transformOrTypeTest(qual: Tree, argType: Type): Tree = argType.dealias match {
104+
def transformTypeTest(qual: Tree, argType: Type): Tree = argType.dealias match {
104105
case OrType(tp1, tp2) =>
105106
evalOnce(qual) { fun =>
106-
transformOrTypeTest(fun, tp1)
107-
.select(nme.OR)
108-
.appliedTo(transformOrTypeTest(fun, tp2))
107+
transformTypeTest(fun, tp1)
108+
.select(defn.Boolean_||)
109+
.appliedTo(transformTypeTest(fun, tp2))
110+
}
111+
case AndType(tp1, tp2) =>
112+
evalOnce(qual) { fun =>
113+
transformTypeTest(fun, tp1)
114+
.select(defn.Boolean_&&)
115+
.appliedTo(transformTypeTest(fun, tp2))
109116
}
110117
case _ =>
111118
transformIsInstanceOf(qual, erasure(argType))
112119
}
113120

114121
if (sym eq defn.Any_isInstanceOf)
115-
transformOrTypeTest(qual, tree.args.head.tpe)
122+
transformTypeTest(qual, tree.args.head.tpe)
116123
else if (sym eq defn.Any_asInstanceOf)
117124
transformAsInstanceOf(erasure(tree.args.head.tpe))
118125
else tree

0 commit comments

Comments
 (0)