diff options
-rw-r--r-- | src/compiler/scala/tools/nsc/transform/Erasure.scala | 6 | ||||
-rw-r--r-- | test/files/neg/bug1872.check | 4 | ||||
-rw-r--r-- | test/files/neg/bug1872.scala | 4 |
3 files changed, 13 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/Erasure.scala b/src/compiler/scala/tools/nsc/transform/Erasure.scala index fa5f899da0..5de5bd9a99 100644 --- a/src/compiler/scala/tools/nsc/transform/Erasure.scala +++ b/src/compiler/scala/tools/nsc/transform/Erasure.scala @@ -983,9 +983,12 @@ abstract class Erasure extends AddInterfaces with typechecker.Analyzer with ast. tree } // todo: also handle the case where the singleton type is buried in a compound - else if (fn.symbol == Any_isInstanceOf) + else if (fn.symbol == Any_isInstanceOf) { fn match { case TypeApply(sel @ Select(qual, name), List(targ)) => + if (qual.tpe != null && isValueClass(qual.tpe.typeSymbol) && targ.tpe != null && targ.tpe <:< AnyRefClass.tpe) + unit.error(sel.pos, "isInstanceOf cannot test if value types are references.") + def mkIsInstanceOf(q: () => Tree)(tp: Type): Tree = Apply( TypeApply( @@ -1009,6 +1012,7 @@ abstract class Erasure extends AddInterfaces with typechecker.Analyzer with ast. } case _ => tree } + } else { def doDynamic(fn: Tree, qual: Tree): Tree = { if (fn.symbol.owner.isRefinementClass && fn.symbol.allOverriddenSymbols.isEmpty) diff --git a/test/files/neg/bug1872.check b/test/files/neg/bug1872.check new file mode 100644 index 0000000000..9f1af33056 --- /dev/null +++ b/test/files/neg/bug1872.check @@ -0,0 +1,4 @@ +bug1872.scala:3: error: isInstanceOf cannot test if value types are references. + def f(x: Int) = x.isInstanceOf[util.Random] + ^ +one error found diff --git a/test/files/neg/bug1872.scala b/test/files/neg/bug1872.scala new file mode 100644 index 0000000000..0ebee0b32d --- /dev/null +++ b/test/files/neg/bug1872.scala @@ -0,0 +1,4 @@ +class A { + // a true result here would necessitate profound soul searching + def f(x: Int) = x.isInstanceOf[util.Random] +}
\ No newline at end of file |