diff options
author | Martin Odersky <odersky@gmail.com> | 2013-12-24 11:59:34 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2013-12-24 12:33:35 +0100 |
commit | b23bc744ce9f8275fb6b433e40f14158eefc1abf (patch) | |
tree | cbeea6b180a011f05c169658f062dfc454eebb3f /src/dotty/tools/dotc/core/Scopes.scala | |
parent | 336a1fc56074b58c54951a4a351d258f23999281 (diff) | |
download | dotty-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/Scopes.scala')
-rw-r--r-- | src/dotty/tools/dotc/core/Scopes.scala | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/dotty/tools/dotc/core/Scopes.scala b/src/dotty/tools/dotc/core/Scopes.scala index b1b81c4a9..ef1ddc8b3 100644 --- a/src/dotty/tools/dotc/core/Scopes.scala +++ b/src/dotty/tools/dotc/core/Scopes.scala @@ -14,6 +14,7 @@ import Periods._ import Decorators._ import Contexts._ import Denotations._ +import SymDenotations._ import printing.Texts._ import printing.Printer import SymDenotations.NoDenotation @@ -102,11 +103,12 @@ object Scopes { } /** The denotation set of all the symbols with given name in this scope */ - final def denotsNamed(name: Name)(implicit ctx: Context): PreDenotation = { + final def denotsNamed(name: Name, select: SymDenotation => Boolean = selectAll)(implicit ctx: Context): PreDenotation = { var syms: PreDenotation = NoDenotation var e = lookupEntry(name) while (e != null) { - syms = syms union e.sym.denot + val d = e.sym.denot + if (select(d)) syms = syms union d e = lookupNextEntry(e) } syms @@ -340,6 +342,10 @@ object Scopes { */ def scopeTransform(owner: Symbol)(op: => MutableScope): MutableScope = op + val selectAll: SymDenotation => Boolean = Function.const(true) + val selectPrivate: SymDenotation => Boolean = d => (d is Flags.Private) + val selectNonPrivate: SymDenotation => Boolean = d => !(d is Flags.Private) + /** The empty scope (immutable). */ object EmptyScope extends Scope { |