diff options
author | Dmitry Petrashko <dmitry.petrashko@gmail.com> | 2014-03-31 14:24:43 +0200 |
---|---|---|
committer | Dmitry Petrashko <dmitry.petrashko@gmail.com> | 2014-04-01 14:39:53 +0200 |
commit | ea5acb56754e26585d2e17080c35a027988660e9 (patch) | |
tree | b9b470bf78fe38256bfc1e43d39bb94657821a84 | |
parent | 2033b5607a41b77590b8d23bf5c40c906a0b42e7 (diff) | |
download | dotty-ea5acb56754e26585d2e17080c35a027988660e9.tar.gz dotty-ea5acb56754e26585d2e17080c35a027988660e9.tar.bz2 dotty-ea5acb56754e26585d2e17080c35a027988660e9.zip |
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])
-rw-r--r-- | src/dotty/tools/dotc/transform/TypeTestsCasts.scala | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/src/dotty/tools/dotc/transform/TypeTestsCasts.scala b/src/dotty/tools/dotc/transform/TypeTestsCasts.scala index 54f72c20c..cbd521210 100644 --- a/src/dotty/tools/dotc/transform/TypeTestsCasts.scala +++ b/src/dotty/tools/dotc/transform/TypeTestsCasts.scala @@ -33,13 +33,13 @@ class TypeTestsCasts extends TreeTransform { def isPrimitive(tp: Type) = tp.classSymbol.isPrimitiveValueClass - def derivedTree(qual1: Tree, sym: Symbol) = - cpy.TypeApply(tree, Select(qual1, sym) withPos qual.pos, tree.args) + def derivedTree(qual1: Tree, sym: Symbol, tp: Type) = + cpy.TypeApply(tree, Select(qual1, sym) withPos qual.pos, List(TypeTree(tp))) def qualCls = qual.tpe.classSymbol - def transformIsInstanceOf(argType: Type): Tree = { - if (qual.tpe <:< argType) + def transformIsInstanceOf(expr:Tree, argType: Type): Tree = { + if (expr.tpe <:< argType) Literal(Constant(true)) withPos tree.pos else if (qualCls.isPrimitiveValueClass) { val argCls = argType.classSymbol @@ -49,11 +49,11 @@ class TypeTestsCasts extends TreeTransform { else argType.dealias match { case _: SingletonType => val cmpOp = if (argType derivesFrom defn.AnyValClass) defn.Any_equals else defn.Object_eq - Apply(Select(qual, cmpOp), singleton(argType) :: Nil) + Apply(Select(expr, cmpOp), singleton(argType) :: Nil) case AndType(tp1, tp2) => - evalOnce(fun) { fun => - val erased1 = transformIsInstanceOf(tp1) - val erased2 = transformIsInstanceOf(tp2) + evalOnce(expr) { fun => + val erased1 = transformIsInstanceOf(fun, tp1) + val erased2 = transformIsInstanceOf(fun, tp2) erased1 match { case Literal(Constant(true)) => erased2 case _ => @@ -68,10 +68,10 @@ class TypeTestsCasts extends TreeTransform { runtimeCall(nme.isArray, arg :: Literal(Constant(ndims)) :: Nil) if (ndims == 1) isArrayTest(qual) else evalOnce(qual) { qual1 => - mkAnd(derivedTree(qual1, defn.Object_isInstanceOf), isArrayTest(qual1)) + mkAnd(derivedTree(qual1, defn.Object_isInstanceOf, qual1.tpe), isArrayTest(qual1)) } case _ => - derivedTree(qual, defn.Object_isInstanceOf) + derivedTree(expr, defn.Object_isInstanceOf, argType) } } @@ -81,14 +81,14 @@ class TypeTestsCasts extends TreeTransform { else if (qualCls.isPrimitiveValueClass) { val argCls = argType.classSymbol if (argCls.isPrimitiveValueClass) primitiveConversion(qual, argCls) - else derivedTree(box(qual), defn.Object_asInstanceOf) + else derivedTree(box(qual), defn.Object_asInstanceOf, argType) } else - derivedTree(qual, defn.Object_asInstanceOf) + derivedTree(qual, defn.Object_asInstanceOf, argType) } if (sym eq defn.Any_isInstanceOf) - transformIsInstanceOf(tree.args.head.tpe) + transformIsInstanceOf(qual, tree.args.head.tpe) else if (defn.asInstanceOfMethods contains sym) transformAsInstanceOf(tree.args.head.tpe) else tree |