summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/compiler/scala/tools/nsc/transform/Erasure.scala4
-rw-r--r--test/files/run/t7763.flags1
-rw-r--r--test/files/run/t7763.scala20
3 files changed, 23 insertions, 2 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/Erasure.scala b/src/compiler/scala/tools/nsc/transform/Erasure.scala
index 0a66ba8a32..5e99a6a933 100644
--- a/src/compiler/scala/tools/nsc/transform/Erasure.scala
+++ b/src/compiler/scala/tools/nsc/transform/Erasure.scala
@@ -680,7 +680,7 @@ abstract class Erasure extends AddInterfaces
private def adaptMember(tree: Tree): Tree = {
//Console.println("adaptMember: " + tree);
tree match {
- case Apply(TypeApply(sel @ Select(qual, name), List(targ)), List())
+ case Apply(ta @ TypeApply(sel @ Select(qual, name), List(targ)), List())
if tree.symbol == Any_asInstanceOf =>
val qual1 = typedQualifier(qual, NOmode, ObjectTpe) // need to have an expected type, see #3037
@@ -705,7 +705,7 @@ abstract class Erasure extends AddInterfaces
// }
typed(untyped)
}
- } else qual1
+ } else treeCopy.Apply(tree, treeCopy.TypeApply(ta, treeCopy.Select(sel, qual1, name), List(targ)), List())
case Apply(TypeApply(sel @ Select(qual, name), List(targ)), List())
if tree.symbol == Any_isInstanceOf =>
diff --git a/test/files/run/t7763.flags b/test/files/run/t7763.flags
new file mode 100644
index 0000000000..7f4215d1bc
--- /dev/null
+++ b/test/files/run/t7763.flags
@@ -0,0 +1 @@
+-Ynooptimize \ No newline at end of file
diff --git a/test/files/run/t7763.scala b/test/files/run/t7763.scala
new file mode 100644
index 0000000000..638077e64a
--- /dev/null
+++ b/test/files/run/t7763.scala
@@ -0,0 +1,20 @@
+object Test {
+ class A; class B
+ def main(args: Array[String]) {
+ def noExpectedType() {
+ a().asInstanceOf[B] // cast elided!
+ }
+ def withExpectedType(): B = {
+ a().asInstanceOf[B]
+ }
+ def test(a: => Any) = try {
+ a
+ sys.error("no CCE!")
+ } catch {case _: ClassCastException => }
+
+ test(noExpectedType())
+ test(withExpectedType())
+ }
+
+ def a(): Object = new A
+}