@@ -33,13 +33,13 @@ class TypeTestsCasts extends TreeTransform {
33
33
34
34
def isPrimitive (tp : Type ) = tp.classSymbol.isPrimitiveValueClass
35
35
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)) )
38
38
39
39
def qualCls = qual.tpe.classSymbol
40
40
41
- def transformIsInstanceOf (argType : Type ): Tree = {
42
- if (qual .tpe <:< argType)
41
+ def transformIsInstanceOf (expr : Tree , argType : Type ): Tree = {
42
+ if (expr .tpe <:< argType)
43
43
Literal (Constant (true )) withPos tree.pos
44
44
else if (qualCls.isPrimitiveValueClass) {
45
45
val argCls = argType.classSymbol
@@ -49,11 +49,11 @@ class TypeTestsCasts extends TreeTransform {
49
49
else argType.dealias match {
50
50
case _ : SingletonType =>
51
51
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 )
53
53
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)
57
57
erased1 match {
58
58
case Literal (Constant (true )) => erased2
59
59
case _ =>
@@ -68,10 +68,10 @@ class TypeTestsCasts extends TreeTransform {
68
68
runtimeCall(nme.isArray, arg :: Literal (Constant (ndims)) :: Nil )
69
69
if (ndims == 1 ) isArrayTest(qual)
70
70
else evalOnce(qual) { qual1 =>
71
- mkAnd(derivedTree(qual1, defn.Object_isInstanceOf ), isArrayTest(qual1))
71
+ mkAnd(derivedTree(qual1, defn.Object_isInstanceOf , qual1.tpe ), isArrayTest(qual1))
72
72
}
73
73
case _ =>
74
- derivedTree(qual , defn.Object_isInstanceOf )
74
+ derivedTree(expr , defn.Object_isInstanceOf , argType )
75
75
}
76
76
}
77
77
@@ -81,14 +81,14 @@ class TypeTestsCasts extends TreeTransform {
81
81
else if (qualCls.isPrimitiveValueClass) {
82
82
val argCls = argType.classSymbol
83
83
if (argCls.isPrimitiveValueClass) primitiveConversion(qual, argCls)
84
- else derivedTree(box(qual), defn.Object_asInstanceOf )
84
+ else derivedTree(box(qual), defn.Object_asInstanceOf , argType )
85
85
}
86
86
else
87
- derivedTree(qual, defn.Object_asInstanceOf )
87
+ derivedTree(qual, defn.Object_asInstanceOf , argType )
88
88
}
89
89
90
90
if (sym eq defn.Any_isInstanceOf )
91
- transformIsInstanceOf(tree.args.head.tpe)
91
+ transformIsInstanceOf(qual, tree.args.head.tpe)
92
92
else if (defn.asInstanceOfMethods contains sym)
93
93
transformAsInstanceOf(tree.args.head.tpe)
94
94
else tree
0 commit comments