summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2012-06-10 23:38:39 +0200
committerJason Zaugg <jzaugg@gmail.com>2012-06-11 00:07:24 +0200
commit617706644139d5731b10b3c77c647e3b70aa07b3 (patch)
tree86c90bc0192870477747adf38ff3f6daab57af2f /src
parent30ef129f322687cbc885d344ca73dd4877fbedd6 (diff)
downloadscala-617706644139d5731b10b3c77c647e3b70aa07b3.tar.gz
scala-617706644139d5731b10b3c77c647e3b70aa07b3.tar.bz2
scala-617706644139d5731b10b3c77c647e3b70aa07b3.zip
SI-5162 Exclude super.foo from the erasure cast of SI-4283
If the target method is defined in Java, treat the super reference as an error, otherwise allow it in the knowledge that Scala loosens the access restrictions on its generated classes. Moves the test for that bug out of pending-ville. It's sufficient to place Test in the empty package to exercise the right code paths.
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/transform/Erasure.scala27
1 files changed, 18 insertions, 9 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/Erasure.scala b/src/compiler/scala/tools/nsc/transform/Erasure.scala
index ce16facf77..1276d62995 100644
--- a/src/compiler/scala/tools/nsc/transform/Erasure.scala
+++ b/src/compiler/scala/tools/nsc/transform/Erasure.scala
@@ -1042,18 +1042,27 @@ abstract class Erasure extends AddInterfaces
assert(overridden != NoSymbol, tree.symbol)
tree.symbol = overridden
}
+
def isAccessible(sym: Symbol) = localTyper.context.isAccessible(sym, sym.owner.thisType)
if (!isAccessible(owner) && qual.tpe != null) {
- // Todo: Figure out how qual.tpe could be null in the check above (it does appear in build where SwingWorker.this
- // has a null type).
- val qualSym = qual.tpe.widen.typeSymbol
- if (isAccessible(qualSym) && !qualSym.isPackageClass && !qualSym.isPackageObjectClass) {
- // insert cast to prevent illegal access error (see #4283)
- // util.trace("insert erasure cast ") (*/
- treeCopy.Select(tree, gen.mkAttributedCast(qual, qual.tpe.widen), name) //)
- } else tree
+ qual match {
+ case Super(_, _) =>
+ // Insert a cast here at your peril -- see SI-5162. Bail out if the target method is defined in
+ // Java, otherwise, we'd get an IllegalAccessError at runtime. If the target method is defined in
+ // Scala, however, we should have access.
+ if (owner.isJavaDefined) unit.error(tree.pos, s"Unable to access ${tree.symbol.fullLocationString} with a super reference.")
+ tree
+ case _ =>
+ // Todo: Figure out how qual.tpe could be null in the check above (it does appear in build where SwingWorker.this
+ // has a null type).
+ val qualSym = qual.tpe.widen.typeSymbol
+ if (isAccessible(qualSym) && !qualSym.isPackageClass && !qualSym.isPackageObjectClass) {
+ // insert cast to prevent illegal access error (see #4283)
+ // util.trace("insert erasure cast ") (*/
+ treeCopy.Select(tree, gen.mkAttributedCast(qual, qual.tpe.widen), name) //)
+ } else tree
+ }
} else tree
-
case Template(parents, self, body) =>
assert(!currentOwner.isImplClass)
//Console.println("checking no dble defs " + tree)//DEBUG