summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoramin <nada.amin@epfl.ch>2012-09-11 15:09:03 +0200
committeramin <nada.amin@epfl.ch>2012-09-17 12:30:57 +0200
commitf6a27140b67fb8e78a3ec777c5b8d6f87fac9ede (patch)
tree0e2f7c91b2312ee3c352cc6809383bb6a6c8a01f
parentd99d38771b03a83d9e2cc576781ea56ea277950f (diff)
downloadscala-f6a27140b67fb8e78a3ec777c5b8d6f87fac9ede.tar.gz
scala-f6a27140b67fb8e78a3ec777c5b8d6f87fac9ede.tar.bz2
scala-f6a27140b67fb8e78a3ec777c5b8d6f87fac9ede.zip
Fix for SI-6245 with workaround for SI-2296.
protected/super accessor issue: Don't subvert the creation of the standard protected accessor with the java interop accessor. For SI-2296, the compiler emits an error instead of causing an illegal access error at runtime. Adapted from e498fac7fdbda3187a2a4fffcdf7fa4f9ddb7ac8. Conflicts: src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala11
-rw-r--r--test/files/neg/t2296a.check5
-rw-r--r--test/files/neg/t2296a/J.java (renamed from test/files/run/t2296a/J.java)0
-rw-r--r--test/files/neg/t2296a/S.scala (renamed from test/files/run/t2296a/S.scala)0
-rw-r--r--test/files/neg/t2296b.check5
-rw-r--r--test/files/neg/t2296b/J_1.java (renamed from test/files/run/t2296b/J_1.java)0
-rw-r--r--test/files/neg/t2296b/S_2.scala (renamed from test/files/run/t2296b/S_2.scala)0
-rw-r--r--test/files/pos/t6245/Base.java5
-rw-r--r--test/files/pos/t6245/Foo.scala9
-rw-r--r--test/files/pos/t6245/Vis.java3
-rw-r--r--test/files/run/t2296a.check2
-rw-r--r--test/files/run/t2296b.check2
12 files changed, 37 insertions, 5 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala b/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala
index 2d6eee35a1..74e246e910 100644
--- a/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala
@@ -241,6 +241,7 @@ abstract class SuperAccessors extends transform.Transform with transform.TypingT
&& !sym.owner.isTrait
&& (sym.owner.enclosingPackageClass != currentPackage)
&& (qual.symbol.info.member(sym.name) ne NoSymbol)
+ && !needsProtectedAccessor(sym, tree.pos)
)
if (shouldEnsureAccessor) {
log("Ensuring accessor for call to protected " + sym.fullLocationString + " from " + currentClass)
@@ -461,7 +462,15 @@ abstract class SuperAccessors extends transform.Transform with transform.TypingT
)
true
}
- isCandidate && !host.isPackageClass && !isSelfType
+ def isJavaProtected = host.isTrait && sym.isJavaDefined && {
+ restrictionError(pos, unit,
+ """|%s accesses protected %s inside a concrete trait method.
+ |Add an accessor in a class extending %s as a workaround.""".stripMargin.format(
+ clazz, sym, sym.enclClass)
+ )
+ true
+ }
+ isCandidate && !host.isPackageClass && !isSelfType && !isJavaProtected
}
/** Return the innermost enclosing class C of referencingClass for which either
diff --git a/test/files/neg/t2296a.check b/test/files/neg/t2296a.check
new file mode 100644
index 0000000000..863b861046
--- /dev/null
+++ b/test/files/neg/t2296a.check
@@ -0,0 +1,5 @@
+S.scala:6: error: Implementation restriction: trait S accesses protected method foo inside a concrete trait method.
+Add an accessor in a class extending class J as a workaround.
+ foo()
+ ^
+one error found
diff --git a/test/files/run/t2296a/J.java b/test/files/neg/t2296a/J.java
index 78ff3e9804..78ff3e9804 100644
--- a/test/files/run/t2296a/J.java
+++ b/test/files/neg/t2296a/J.java
diff --git a/test/files/run/t2296a/S.scala b/test/files/neg/t2296a/S.scala
index 532d038a42..532d038a42 100644
--- a/test/files/run/t2296a/S.scala
+++ b/test/files/neg/t2296a/S.scala
diff --git a/test/files/neg/t2296b.check b/test/files/neg/t2296b.check
new file mode 100644
index 0000000000..07cc54d573
--- /dev/null
+++ b/test/files/neg/t2296b.check
@@ -0,0 +1,5 @@
+S_2.scala:6: error: Implementation restriction: trait S accesses protected method foo inside a concrete trait method.
+Add an accessor in a class extending class J_1 as a workaround.
+ foo()
+ ^
+one error found
diff --git a/test/files/run/t2296b/J_1.java b/test/files/neg/t2296b/J_1.java
index 4c91d47073..4c91d47073 100644
--- a/test/files/run/t2296b/J_1.java
+++ b/test/files/neg/t2296b/J_1.java
diff --git a/test/files/run/t2296b/S_2.scala b/test/files/neg/t2296b/S_2.scala
index 6cdb0cfaba..6cdb0cfaba 100644
--- a/test/files/run/t2296b/S_2.scala
+++ b/test/files/neg/t2296b/S_2.scala
diff --git a/test/files/pos/t6245/Base.java b/test/files/pos/t6245/Base.java
new file mode 100644
index 0000000000..651ea08bf2
--- /dev/null
+++ b/test/files/pos/t6245/Base.java
@@ -0,0 +1,5 @@
+package t1;
+
+public class Base {
+ protected Vis inner;
+}
diff --git a/test/files/pos/t6245/Foo.scala b/test/files/pos/t6245/Foo.scala
new file mode 100644
index 0000000000..f5f997fbff
--- /dev/null
+++ b/test/files/pos/t6245/Foo.scala
@@ -0,0 +1,9 @@
+import t1.Vis
+
+abstract class Foo extends t1.Base {
+ trait Nested {
+ def crash() {
+ inner
+ }
+ }
+}
diff --git a/test/files/pos/t6245/Vis.java b/test/files/pos/t6245/Vis.java
new file mode 100644
index 0000000000..4267f4e40b
--- /dev/null
+++ b/test/files/pos/t6245/Vis.java
@@ -0,0 +1,3 @@
+package t1;
+
+public class Vis { }
diff --git a/test/files/run/t2296a.check b/test/files/run/t2296a.check
deleted file mode 100644
index f75aec9d81..0000000000
--- a/test/files/run/t2296a.check
+++ /dev/null
@@ -1,2 +0,0 @@
-J.foo()
-J.foo()
diff --git a/test/files/run/t2296b.check b/test/files/run/t2296b.check
deleted file mode 100644
index f75aec9d81..0000000000
--- a/test/files/run/t2296b.check
+++ /dev/null
@@ -1,2 +0,0 @@
-J.foo()
-J.foo()