aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/core/SymDenotations.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2013-12-24 11:59:34 +0100
committerMartin Odersky <odersky@gmail.com>2013-12-24 12:33:35 +0100
commitb23bc744ce9f8275fb6b433e40f14158eefc1abf (patch)
treecbeea6b180a011f05c169658f062dfc454eebb3f /src/dotty/tools/dotc/core/SymDenotations.scala
parent336a1fc56074b58c54951a4a351d258f23999281 (diff)
downloaddotty-b23bc744ce9f8275fb6b433e40f14158eefc1abf.tar.gz
dotty-b23bc744ce9f8275fb6b433e40f14158eefc1abf.tar.bz2
dotty-b23bc744ce9f8275fb6b433e40f14158eefc1abf.zip
Fixing problems in treatment of private symbols
1) Accessibility check was broken because it looked at symbol's owner, where it should have looked at context owner. 2) Refined treatement if members. Previously, nonPrivate member returned a subset of member, i.e. those denotations returned by member that were not private. This is not correct. In a situation like class A { def x: Int = 1 } class B { private def x: String = "" } extends A (new B).x the non-private member returned should be A#x. Changed membersNamed and friends as well as checkAccessible to account for that.
Diffstat (limited to 'src/dotty/tools/dotc/core/SymDenotations.scala')
-rw-r--r--src/dotty/tools/dotc/core/SymDenotations.scala31
1 files changed, 20 insertions, 11 deletions
diff --git a/src/dotty/tools/dotc/core/SymDenotations.scala b/src/dotty/tools/dotc/core/SymDenotations.scala
index a3ce8af6e..c36727c2b 100644
--- a/src/dotty/tools/dotc/core/SymDenotations.scala
+++ b/src/dotty/tools/dotc/core/SymDenotations.scala
@@ -385,9 +385,9 @@ object SymDenotations {
/** Are we inside definition of `boundary`? */
def accessWithin(boundary: Symbol) =
- owner.isContainedIn(boundary) &&
+ ctx.owner.isContainedIn(boundary) &&
(!(this is JavaDefined) || // disregard package nesting for Java
- owner.enclosingPackage == boundary.enclosingPackage)
+ ctx.owner.enclosingPackage == boundary.enclosingPackage)
/** Are we within definition of linked class of `boundary`? */
def accessWithinLinked(boundary: Symbol) = {
@@ -938,21 +938,30 @@ object SymDenotations {
* The elements of the returned pre-denotation all
* have existing symbols.
*/
- final def membersNamed(name: Name)(implicit ctx: Context): PreDenotation =
+ final def membersNamed(name: Name)(implicit ctx: Context): PreDenotation = {
+ val privates = decls.denotsNamed(name, selectPrivate)
+ privates union nonPrivateMembersNamed(name).filterDisjoint(privates)
+ }
+
+ /** All non-private members of this class that have the given name.
+ * The elements of the returned pre-denotation all
+ * have existing symbols.
+ */
+ final def nonPrivateMembersNamed(name: Name)(implicit ctx: Context): PreDenotation =
if (Config.cacheMembersNamed) {
var denots: PreDenotation = memberCache lookup name
if (denots == null) {
- denots = computeMembersNamed(name)
+ denots = computeNPMembersNamed(name)
memberCache enter (name, denots)
}
denots
- } else computeMembersNamed(name)
+ } else computeNPMembersNamed(name)
- private def computeMembersNamed(name: Name)(implicit ctx: Context): PreDenotation =
+ private def computeNPMembersNamed(name: Name)(implicit ctx: Context): PreDenotation =
if (!classSymbol.hasChildren ||
!Config.useFingerPrints ||
(memberFingerPrint contains name)) {
- val ownDenots = decls.denotsNamed(name)
+ val ownDenots = decls.denotsNamed(name, selectNonPrivate)
if (debugTrace) // DEBUG
println(s"$this.member($name), ownDenots = $ownDenots")
def collect(denots: PreDenotation, parents: List[TypeRef]): PreDenotation = parents match {
@@ -973,10 +982,10 @@ object SymDenotations {
else collect(ownDenots, classParents)
} else NoDenotation
- override final def findMember(name: Name, pre: Type, excluded: FlagSet)(implicit ctx: Context): Denotation =
- //ctx.typeComparer.traceIndented(s"($this).findMember($name, $pre)") { // DEBUG
- membersNamed(name).filterExcluded(excluded).asSeenFrom(pre).toDenot(pre)
- //}
+ override final def findMember(name: Name, pre: Type, excluded: FlagSet)(implicit ctx: Context): Denotation = {
+ val raw = if (excluded is Private) nonPrivateMembersNamed(name) else membersNamed(name)
+ raw.filterExcluded(excluded).asSeenFrom(pre).toDenot(pre)
+ }
private[this] var baseTypeCache: java.util.HashMap[CachedType, Type] = null
private[this] var baseTypeValid: RunId = NoRunId