diff options
author | Martin Odersky <odersky@gmail.com> | 2014-08-28 18:22:13 +0200 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2014-08-28 18:22:13 +0200 |
commit | 7663191c433e101e3e4faab2e0db12c5f4db1fc2 (patch) | |
tree | 026595637a33b698779f532778db847b9182502f /src | |
parent | bfb328ff64dcfa103c91dd0cd55a617e370d6ef3 (diff) | |
download | dotty-7663191c433e101e3e4faab2e0db12c5f4db1fc2.tar.gz dotty-7663191c433e101e3e4faab2e0db12c5f4db1fc2.tar.bz2 dotty-7663191c433e101e3e4faab2e0db12c5f4db1fc2.zip |
Fixes in TypeTestsCast
1) qualifier class was wrongly computed
2) Case where test or cast argument is primitive was not fully handled.
Diffstat (limited to 'src')
-rw-r--r-- | src/dotty/tools/dotc/transform/TypeTestsCasts.scala | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/dotty/tools/dotc/transform/TypeTestsCasts.scala b/src/dotty/tools/dotc/transform/TypeTestsCasts.scala index ce5235e63..f74f4f208 100644 --- a/src/dotty/tools/dotc/transform/TypeTestsCasts.scala +++ b/src/dotty/tools/dotc/transform/TypeTestsCasts.scala @@ -12,10 +12,10 @@ import core.StdNames._ import core.TypeErasure.isUnboundedGeneric import typer.ErrorReporting._ import ast.Trees._ -import Erasure.Boxing.box +import Erasure.Boxing._ /** This transform normalizes type tests and type casts, - * also replacing type tests with singleton argument type with refference equality check + * also replacing type tests with singleton argument type with reference equality check * Any remaining type tests * - use the object methods $isInstanceOf and $asInstanceOf * - have a reference type as receiver @@ -36,16 +36,18 @@ class TypeTestsCasts extends MiniPhaseTransform { def derivedTree(qual1: Tree, sym: Symbol, tp: Type) = cpy.TypeApply(tree)(qual1.select(sym).withPos(qual.pos), List(TypeTree(tp))) - def qualCls = qual.tpe.classSymbol + def qualCls = qual.tpe.widen.classSymbol def transformIsInstanceOf(expr:Tree, argType: Type): Tree = { + def argCls = argType.classSymbol if (expr.tpe <:< argType) Literal(Constant(true)) withPos tree.pos else if (qualCls.isPrimitiveValueClass) { - val argCls = argType.classSymbol if (argCls.isPrimitiveValueClass) Literal(Constant(qualCls == argCls)) else errorTree(tree, "isInstanceOf cannot test if value types are references") } + else if (argCls.isPrimitiveValueClass) + transformIsInstanceOf(expr, defn.boxedClass(argCls).typeRef) else argType.dealias match { case _: SingletonType => val cmpOp = if (argType derivesFrom defn.AnyValClass) defn.Any_equals else defn.Object_eq @@ -76,13 +78,15 @@ class TypeTestsCasts extends MiniPhaseTransform { } def transformAsInstanceOf(argType: Type): Tree = { + def argCls = argType.classSymbol if (qual.tpe <:< argType) Typed(qual, tree.args.head) else if (qualCls.isPrimitiveValueClass) { - val argCls = argType.classSymbol if (argCls.isPrimitiveValueClass) primitiveConversion(qual, argCls) else derivedTree(box(qual), defn.Any_asInstanceOf, argType) } + else if (argCls.isPrimitiveValueClass) + unbox(qual, argType) else derivedTree(qual, defn.Any_asInstanceOf, argType) } |