Skip to content

Commit fef2f42

Browse files
committed
Fix TypeTestCasts
def p() = println().isInstanceOf[Long & Int] was rewritten to val ev$1: [T0]Boolean(x.isInstanceOf) = println().isInstanceOf println().$isInstanceOf[Long & Int].&&(println().$isInstanceOf[Long & Int])
1 parent fb9a9e6 commit fef2f42

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ class TypeTestsCasts extends TreeTransform {
3333

3434
def isPrimitive(tp: Type) = tp.classSymbol.isPrimitiveValueClass
3535

36-
def derivedTree(qual1: Tree, sym: Symbol) =
37-
cpy.TypeApply(tree, Select(qual1, sym) withPos qual.pos, tree.args)
36+
def derivedTree(qual1: Tree, sym: Symbol, tp: Type) =
37+
cpy.TypeApply(tree, Select(qual1, sym) withPos qual.pos, List(TypeTree(tp)))
3838

3939
def qualCls = qual.tpe.classSymbol
4040

41-
def transformIsInstanceOf(argType: Type): Tree = {
42-
if (qual.tpe <:< argType)
41+
def transformIsInstanceOf(expr:Tree, argType: Type): Tree = {
42+
if (expr.tpe <:< argType)
4343
Literal(Constant(true)) withPos tree.pos
4444
else if (qualCls.isPrimitiveValueClass) {
4545
val argCls = argType.classSymbol
@@ -49,11 +49,11 @@ class TypeTestsCasts extends TreeTransform {
4949
else argType.dealias match {
5050
case _: SingletonType =>
5151
val cmpOp = if (argType derivesFrom defn.AnyValClass) defn.Any_equals else defn.Object_eq
52-
Apply(Select(qual, cmpOp), singleton(argType) :: Nil)
52+
Apply(Select(expr, cmpOp), singleton(argType) :: Nil)
5353
case AndType(tp1, tp2) =>
54-
evalOnce(fun) { fun =>
55-
val erased1 = transformIsInstanceOf(tp1)
56-
val erased2 = transformIsInstanceOf(tp2)
54+
evalOnce(expr) { fun =>
55+
val erased1 = transformIsInstanceOf(fun, tp1)
56+
val erased2 = transformIsInstanceOf(fun, tp2)
5757
erased1 match {
5858
case Literal(Constant(true)) => erased2
5959
case _ =>
@@ -68,10 +68,10 @@ class TypeTestsCasts extends TreeTransform {
6868
runtimeCall(nme.isArray, arg :: Literal(Constant(ndims)) :: Nil)
6969
if (ndims == 1) isArrayTest(qual)
7070
else evalOnce(qual) { qual1 =>
71-
mkAnd(derivedTree(qual1, defn.Object_isInstanceOf), isArrayTest(qual1))
71+
mkAnd(derivedTree(qual1, defn.Object_isInstanceOf, qual1.tpe), isArrayTest(qual1))
7272
}
7373
case _ =>
74-
derivedTree(qual, defn.Object_isInstanceOf)
74+
derivedTree(expr, defn.Object_isInstanceOf, argType)
7575
}
7676
}
7777

@@ -81,14 +81,14 @@ class TypeTestsCasts extends TreeTransform {
8181
else if (qualCls.isPrimitiveValueClass) {
8282
val argCls = argType.classSymbol
8383
if (argCls.isPrimitiveValueClass) primitiveConversion(qual, argCls)
84-
else derivedTree(box(qual), defn.Object_asInstanceOf)
84+
else derivedTree(box(qual), defn.Object_asInstanceOf, argType)
8585
}
8686
else
87-
derivedTree(qual, defn.Object_asInstanceOf)
87+
derivedTree(qual, defn.Object_asInstanceOf, argType)
8888
}
8989

9090
if (sym eq defn.Any_isInstanceOf)
91-
transformIsInstanceOf(tree.args.head.tpe)
91+
transformIsInstanceOf(qual, tree.args.head.tpe)
9292
else if (defn.asInstanceOfMethods contains sym)
9393
transformAsInstanceOf(tree.args.head.tpe)
9494
else tree

0 commit comments

Comments
 (0)