summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2016-11-18 15:29:53 +1000
committerJason Zaugg <jzaugg@gmail.com>2016-11-18 15:33:58 +1000
commitd2d33ddf8ce4dff503c8830958bac0e449eb7d34 (patch)
tree4a27ed92ff8c831ee97bd173685c45f6ca5b0d84
parent73678d4dafe250f0b38df2e953787af26b1a4ee3 (diff)
downloadscala-d2d33ddf8ce4dff503c8830958bac0e449eb7d34.tar.gz
scala-d2d33ddf8ce4dff503c8830958bac0e449eb7d34.tar.bz2
scala-d2d33ddf8ce4dff503c8830958bac0e449eb7d34.zip
SI-10067 Java defined inner classes don't have outer accessors
If we pretend they do, we can walk into NoSuchMethodErrors when translating type patterns path dependent types. This commit avoids this symptom by changing the explicitouter info transformer. A following commit will change the pattern matcher itself to avoid speculatively adding this outer check that will be always dropped in explicitouter.
-rw-r--r--src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala2
-rw-r--r--test/files/run/t10067.check3
-rw-r--r--test/files/run/t10067.flags1
-rw-r--r--test/files/run/t10067/OuterClass.java7
-rw-r--r--test/files/run/t10067/Test.scala19
5 files changed, 31 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala b/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala
index 7d50c12852..8bdbf16e03 100644
--- a/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala
+++ b/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala
@@ -166,7 +166,7 @@ abstract class ExplicitOuter extends InfoTransform
if ((resTpTransformed ne resTp) || (paramsWithOuter ne params)) MethodType(paramsWithOuter, resTpTransformed)
else tp
- case ClassInfoType(parents, decls, clazz) =>
+ case ClassInfoType(parents, decls, clazz) if !clazz.isJava =>
var decls1 = decls
if (isInner(clazz) && !clazz.isInterface) {
decls1 = decls.cloneScope
diff --git a/test/files/run/t10067.check b/test/files/run/t10067.check
new file mode 100644
index 0000000000..7e8e5ce4b9
--- /dev/null
+++ b/test/files/run/t10067.check
@@ -0,0 +1,3 @@
+Test.scala:16: warning: The outer reference in this type test cannot be checked at run time.
+ case ic: ocStable.InnerClass => ;
+ ^
diff --git a/test/files/run/t10067.flags b/test/files/run/t10067.flags
new file mode 100644
index 0000000000..c02e5f2461
--- /dev/null
+++ b/test/files/run/t10067.flags
@@ -0,0 +1 @@
+-unchecked
diff --git a/test/files/run/t10067/OuterClass.java b/test/files/run/t10067/OuterClass.java
new file mode 100644
index 0000000000..15c2c990d7
--- /dev/null
+++ b/test/files/run/t10067/OuterClass.java
@@ -0,0 +1,7 @@
+public class OuterClass {
+ public class InnerClass { }
+
+ public Object getInnerClassInstance() {
+ return new InnerClass();
+ }
+}
diff --git a/test/files/run/t10067/Test.scala b/test/files/run/t10067/Test.scala
new file mode 100644
index 0000000000..af1e12592e
--- /dev/null
+++ b/test/files/run/t10067/Test.scala
@@ -0,0 +1,19 @@
+object Test {
+ def main(args: Array[String]): Unit = {
+ //get inner class as some instance of super type
+ var oc = new OuterClass();
+ var icObj = oc.getInnerClassInstance();
+
+ //get a stable identifier on outer class
+ val ocStable = oc;
+
+ //these will work
+ icObj.isInstanceOf[ocStable.InnerClass];
+ icObj.asInstanceOf[ocStable.InnerClass];
+
+ //this will fail with java.lang.NoSuchMethodError
+ icObj match {
+ case ic: ocStable.InnerClass => ;
+ }
+ }
+}