diff options
Diffstat (limited to 'src/dotty')
-rw-r--r-- | src/dotty/tools/dotc/transform/TypeTestsCasts.scala | 7 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/RefChecks.scala | 16 |
2 files changed, 18 insertions, 5 deletions
diff --git a/src/dotty/tools/dotc/transform/TypeTestsCasts.scala b/src/dotty/tools/dotc/transform/TypeTestsCasts.scala index 562efef97..7aaf7d86d 100644 --- a/src/dotty/tools/dotc/transform/TypeTestsCasts.scala +++ b/src/dotty/tools/dotc/transform/TypeTestsCasts.scala @@ -47,12 +47,9 @@ trait TypeTestsCasts { def argCls = argType.classSymbol if (expr.tpe <:< argType) Literal(Constant(true)) withPos tree.pos - else if (qualCls.isPrimitiveValueClass) { - 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) + if (qualCls.isPrimitiveValueClass) Literal(Constant(qualCls == argCls)) + else 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 diff --git a/src/dotty/tools/dotc/typer/RefChecks.scala b/src/dotty/tools/dotc/typer/RefChecks.scala index 2b81af5cb..f45966741 100644 --- a/src/dotty/tools/dotc/typer/RefChecks.scala +++ b/src/dotty/tools/dotc/typer/RefChecks.scala @@ -814,6 +814,22 @@ class RefChecks extends MiniPhase with SymTransformer { thisTransformer => currentLevel.enterReference(tree.tpe.typeSymbol, tree.pos) tree } + + override def transformTypeApply(tree: tpd.TypeApply)(implicit ctx: Context, info: TransformerInfo): tpd.Tree = { + tree.fun match { + case fun@Select(qual, selector) => + val sym = tree.symbol + + if (sym == defn.Any_isInstanceOf) { + val argType = tree.args.head.tpe + val qualCls = qual.tpe.widen.classSymbol + val argCls = argType.classSymbol + if (qualCls.isPrimitiveValueClass && !argCls.isPrimitiveValueClass) ctx.error("isInstanceOf cannot test if value types are references", tree.pos) + } + case _ => + } + tree + } } } |