Permalink
Browse files

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 e498fac.

Conflicts:

	src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala
  • Loading branch information...
1 parent d99d387 commit f6a27140b67fb8e78a3ec777c5b8d6f87fac9ede @namin namin committed Sep 11, 2012
@@ -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
@@ -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
File renamed without changes.
File renamed without changes.
@@ -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
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,5 @@
+package t1;
+
+public class Base {
+ protected Vis inner;
+}
@@ -0,0 +1,9 @@
+import t1.Vis
+
+abstract class Foo extends t1.Base {
+ trait Nested {
+ def crash() {
+ inner
+ }
+ }
+}
@@ -0,0 +1,3 @@
+package t1;
+
+public class Vis { }
@@ -1,2 +0,0 @@
-J.foo()
-J.foo()
@@ -1,2 +0,0 @@
-J.foo()
-J.foo()

0 comments on commit f6a2714

Please sign in to comment.