diff options
author | Iulian Dragos <jaguarul@gmail.com> | 2010-06-11 09:34:42 +0000 |
---|---|---|
committer | Iulian Dragos <jaguarul@gmail.com> | 2010-06-11 09:34:42 +0000 |
commit | a2875b700b5d25217ad1b8ae416bd452e67df0be (patch) | |
tree | 4848460997835fb301c4996c213b33491c75c190 | |
parent | 8512b81f4e0b173f99cd1e80ac31c4fa4f3da5ff (diff) | |
download | scala-a2875b700b5d25217ad1b8ae416bd452e67df0be.tar.gz scala-a2875b700b5d25217ad1b8ae416bd452e67df0be.tar.bz2 scala-a2875b700b5d25217ad1b8ae416bd452e67df0be.zip |
Partial fix for #2296: instead of VerifyError w...
Partial fix for #2296: instead of VerifyError we issue a compile-time
error (implementation restriction). To properly generate accessors in
traits we need to move most (all?) logic related to protected accessors
to phase mixin, use abstract accessors all the way up to mixin, and
generate the code in the mixin class. In other words, exactly what is
done for super accessors right now. Review by extempore.
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala b/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala index fabf2ed063..0c3ac481ed 100644 --- a/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala +++ b/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala @@ -411,10 +411,15 @@ abstract class SuperAccessors extends transform.Transform with transform.TypingT unit.error(pos, "Implementation restriction: " + msg) } + def accessibleThroughSubclassing: Boolean = + (validCurrentOwner + && currentOwner.enclClass.thisSym.isSubClass(sym.owner) + && !currentOwner.enclClass.isTrait) + val res = /* settings.debug.value && */ ((sym hasFlag PROTECTED) && !sym.owner.isPackageClass - && (!validCurrentOwner || !(currentOwner.enclClass.thisSym isSubClass sym.owner)) + && !accessibleThroughSubclassing && (enclPackage(sym.owner) != enclPackage(currentOwner)) && (enclPackage(sym.owner) == enclPackage(sym.accessBoundary(sym.owner)))) @@ -424,9 +429,12 @@ abstract class SuperAccessors extends transform.Transform with transform.TypingT if (host.isPackageClass) false else if (host.thisSym != host) { if (host.thisSym.tpe.typeSymbol.hasFlag(JAVA)) - errorRestriction(currentOwner.enclClass + " accesses protected " + sym - + " from self type " + host.thisSym.tpe) + errorRestriction("%s accesses protected %s from self type %s.".format(currentOwner.enclClass, sym, host.thisSym.tpe)) false + } else if (host.isTrait && sym.hasFlag(JAVA)) { + errorRestriction(("%s accesses protected %s inside a concrete trait method. " + + "Add an accessor in a class extending %s to work around this bug.").format(currentOwner.enclClass, sym, sym.enclClass)) + false } else res } else res } |