summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugene Burmako <xeno.by@gmail.com>2012-07-30 13:17:17 +0200
committerEugene Burmako <xeno.by@gmail.com>2012-08-02 15:36:55 +0200
commita727c6fc198d33842ff85d8a16d48143a6757d51 (patch)
tree3b995ade8066488c3ac42d7b65e0bb02b976cabc
parent937da62be2834a646a31dbfb01527a82672f111e (diff)
downloadscala-a727c6fc198d33842ff85d8a16d48143a6757d51.tar.gz
scala-a727c6fc198d33842ff85d8a16d48143a6757d51.tar.bz2
scala-a727c6fc198d33842ff85d8a16d48143a6757d51.zip
SI-5732 members and derivatives now return Scope
Firstly this unifies the reflection API - now both decls and members return Scope (not Scope and List[Symbol] as it were before). Secondly this fixes SI-5732 without having to sort the result of members. Type.members now returns Scope, a distinguished type, which has the `sorted` method, which does the required sorting if necessary. Also removes nonPrivateMembers and nonPrivateDeclarations to keep the API minimalistic (as can be seen from their implementation in internal.Types they are just members and decls with bridges and private members removed).
-rw-r--r--src/compiler/scala/tools/nsc/doc/model/ModelFactory.scala4
-rw-r--r--src/compiler/scala/tools/nsc/doc/model/ModelFactoryImplicitSupport.scala2
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/Imports.scala2
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/JLineCompletion.scala8
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/MemberHandlers.scala2
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/Power.scala4
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Contexts.scala10
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Implicits.scala2
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/RefChecks.scala4
-rw-r--r--src/library/scala/reflect/base/Base.scala13
-rw-r--r--src/library/scala/reflect/base/Scopes.scala22
-rw-r--r--src/reflect/scala/reflect/api/Types.scala31
-rw-r--r--src/reflect/scala/reflect/internal/Scopes.scala50
-rw-r--r--src/reflect/scala/reflect/internal/Symbols.scala4
-rw-r--r--src/reflect/scala/reflect/internal/Types.scala22
-rw-r--r--src/reflect/scala/reflect/runtime/SynchronizedSymbols.scala2
-rw-r--r--test/files/run/reflection-simple.scala12
-rw-r--r--test/files/run/reflection-sorted-decls.check7
-rw-r--r--test/files/run/reflection-sorted-decls.scala8
-rw-r--r--test/files/run/reflection-sorted-members.check (renamed from test/files/run/reflection-simple.check)79
-rw-r--r--test/files/run/reflection-sorted-members.scala11
21 files changed, 178 insertions, 121 deletions
diff --git a/src/compiler/scala/tools/nsc/doc/model/ModelFactory.scala b/src/compiler/scala/tools/nsc/doc/model/ModelFactory.scala
index 00e6f3769e..8805f68634 100644
--- a/src/compiler/scala/tools/nsc/doc/model/ModelFactory.scala
+++ b/src/compiler/scala/tools/nsc/doc/model/ModelFactory.scala
@@ -380,7 +380,7 @@ class ModelFactory(val global: Global, val settings: doc.Settings) {
if (settings.docImplicits.value) makeImplicitConversions(sym, this) else Nil
// members as given by the compiler
- lazy val memberSyms = sym.info.members.filter(s => membersShouldDocument(s, this))
+ lazy val memberSyms = sym.info.members.filter(s => membersShouldDocument(s, this)).toList
// the inherited templates (classes, traits or objects)
var memberSymsLazy = memberSyms.filter(t => templateShouldDocument(t, this) && !inOriginalOwner(t, this))
@@ -712,7 +712,7 @@ class ModelFactory(val global: Global, val settings: doc.Settings) {
override def inheritedFrom = Nil
override def isRootPackage = true
override lazy val memberSyms =
- (bSym.info.members ++ EmptyPackage.info.members) filter { s =>
+ (bSym.info.members ++ EmptyPackage.info.members).toList filter { s =>
s != EmptyPackage && s != RootPackage
}
})
diff --git a/src/compiler/scala/tools/nsc/doc/model/ModelFactoryImplicitSupport.scala b/src/compiler/scala/tools/nsc/doc/model/ModelFactoryImplicitSupport.scala
index a12b67c9ed..5a0cc602e5 100644
--- a/src/compiler/scala/tools/nsc/doc/model/ModelFactoryImplicitSupport.scala
+++ b/src/compiler/scala/tools/nsc/doc/model/ModelFactoryImplicitSupport.scala
@@ -386,7 +386,7 @@ trait ModelFactoryImplicitSupport {
lazy val memberImpls: List[MemberImpl] = {
// Obtain the members inherited by the implicit conversion
- val memberSyms = toType.members.filter(implicitShouldDocument(_))
+ val memberSyms = toType.members.filter(implicitShouldDocument(_)).toList
val existingSyms = sym.info.members
// Debugging part :)
diff --git a/src/compiler/scala/tools/nsc/interpreter/Imports.scala b/src/compiler/scala/tools/nsc/interpreter/Imports.scala
index d579e0369e..5e72d2b661 100644
--- a/src/compiler/scala/tools/nsc/interpreter/Imports.scala
+++ b/src/compiler/scala/tools/nsc/interpreter/Imports.scala
@@ -191,5 +191,5 @@ trait Imports {
prevRequestList flatMap (req => req.handlers map (req -> _))
private def membersAtPickler(sym: Symbol): List[Symbol] =
- beforePickler(sym.info.nonPrivateMembers)
+ beforePickler(sym.info.nonPrivateMembers.toList)
} \ No newline at end of file
diff --git a/src/compiler/scala/tools/nsc/interpreter/JLineCompletion.scala b/src/compiler/scala/tools/nsc/interpreter/JLineCompletion.scala
index c429e3b196..b9849e40d1 100644
--- a/src/compiler/scala/tools/nsc/interpreter/JLineCompletion.scala
+++ b/src/compiler/scala/tools/nsc/interpreter/JLineCompletion.scala
@@ -52,10 +52,10 @@ class JLineCompletion(val intp: IMain) extends Completion with CompletionOutput
// XXX we'd like to say "filterNot (_.isDeprecated)" but this causes the
// compiler to crash for reasons not yet known.
- def members = afterTyper((effectiveTp.nonPrivateMembers ++ anyMembers) filter (_.isPublic))
- def methods = members filter (_.isMethod)
- def packages = members filter (_.isPackage)
- def aliases = members filter (_.isAliasType)
+ def members = afterTyper((effectiveTp.nonPrivateMembers.toList ++ anyMembers) filter (_.isPublic))
+ def methods = members.toList filter (_.isMethod)
+ def packages = members.toList filter (_.isPackage)
+ def aliases = members.toList filter (_.isAliasType)
def memberNames = members map tos
def methodNames = methods map tos
diff --git a/src/compiler/scala/tools/nsc/interpreter/MemberHandlers.scala b/src/compiler/scala/tools/nsc/interpreter/MemberHandlers.scala
index 236f3f23c5..b0c20f3d0c 100644
--- a/src/compiler/scala/tools/nsc/interpreter/MemberHandlers.scala
+++ b/src/compiler/scala/tools/nsc/interpreter/MemberHandlers.scala
@@ -211,7 +211,7 @@ trait MemberHandlers {
beforePickler(individualNames map (targetType nonPrivateMember _))
lazy val wildcardSymbols: List[Symbol] =
- if (importsWildcard) beforePickler(targetType.nonPrivateMembers)
+ if (importsWildcard) beforePickler(targetType.nonPrivateMembers.toList)
else Nil
/** Complete list of names imported by a wildcard */
diff --git a/src/compiler/scala/tools/nsc/interpreter/Power.scala b/src/compiler/scala/tools/nsc/interpreter/Power.scala
index 57d7cef726..ebc02d98ed 100644
--- a/src/compiler/scala/tools/nsc/interpreter/Power.scala
+++ b/src/compiler/scala/tools/nsc/interpreter/Power.scala
@@ -62,7 +62,7 @@ class Power[ReplValsImpl <: ReplVals : ru.TypeTag: ClassTag](val intp: IMain, re
def discarded = seen.size - keep.size
def members(x: Symbol): List[Symbol] =
- if (x.rawInfo.isComplete) x.info.members
+ if (x.rawInfo.isComplete) x.info.members.toList
else Nil
var lastCount = -1
@@ -216,7 +216,7 @@ class Power[ReplValsImpl <: ReplVals : ru.TypeTag: ClassTag](val intp: IMain, re
def declsOriginal = membersDeclared filterNot (_.isOverride)
def members = membersUnabridged filterNot excludeMember
- def membersUnabridged = tpe.members
+ def membersUnabridged = tpe.members.toList
def membersDeclared = members filterNot excludeMember
def membersInherited = members filterNot (membersDeclared contains _)
def memberTypes = members filter (_.name.isTypeName)
diff --git a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
index 0fc298e886..c7dab69f62 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
@@ -360,7 +360,7 @@ trait Contexts { self: Analyzer =>
private def unitError(pos: Position, msg: String) =
unit.error(pos, if (checking) "\n**** ERROR DURING INTERNAL CHECKING ****\n" + msg else msg)
-
+
@inline private def issueCommon(err: AbsTypeError)(pf: PartialFunction[AbsTypeError, Unit]) {
debugwarn("issue error: " + err.errMsg)
if (settings.Yissuedebug.value) (new Exception).printStackTrace()
@@ -611,8 +611,8 @@ trait Contexts { self: Analyzer =>
(e ne null) && (e.owner == scope)
})
- private def collectImplicits(syms: List[Symbol], pre: Type, imported: Boolean = false): List[ImplicitInfo] =
- for (sym <- syms if isQualifyingImplicit(sym.name, sym, pre, imported)) yield
+ private def collectImplicits(syms: Scope, pre: Type, imported: Boolean = false): List[ImplicitInfo] =
+ for (sym <- syms.toList if isQualifyingImplicit(sym.name, sym, pre, imported)) yield
new ImplicitInfo(sym.name, pre, sym)
private def collectImplicitImports(imp: ImportInfo): List[ImplicitInfo] = {
@@ -657,7 +657,7 @@ trait Contexts { self: Analyzer =>
}
} else if (scope != nextOuter.scope && !owner.isPackageClass) {
debuglog("collect local implicits " + scope.toList)//DEBUG
- collectImplicits(scope.toList, NoPrefix)
+ collectImplicits(scope, NoPrefix)
} else if (imports != nextOuter.imports) {
assert(imports.tail == nextOuter.imports, (imports, nextOuter.imports))
collectImplicitImports(imports.head)
@@ -725,7 +725,7 @@ trait Contexts { self: Analyzer =>
result
}
- def allImportedSymbols: List[Symbol] =
+ def allImportedSymbols: Iterable[Symbol] =
qual.tpe.members flatMap (transformImport(tree.selectors, _))
private def transformImport(selectors: List[ImportSelector], sym: Symbol): List[Symbol] = selectors match {
diff --git a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala
index da045e1a48..529f5408a2 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala
@@ -957,7 +957,7 @@ trait Implicits {
companion.moduleClass match {
case mc: ModuleClassSymbol =>
val infos =
- for (im <- mc.implicitMembers) yield new ImplicitInfo(im.name, singleType(pre, companion), im)
+ for (im <- mc.implicitMembers.toList) yield new ImplicitInfo(im.name, singleType(pre, companion), im)
if (infos.nonEmpty)
infoMap += (sym -> infos)
case _ =>
diff --git a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
index 3518316fbb..9501998152 100644
--- a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
@@ -122,7 +122,7 @@ abstract class RefChecks extends InfoTransform with reflect.internal.transform.R
val defaultGetters = clazz.info.findMembers(0L, DEFAULTPARAM)
val defaultMethodNames = defaultGetters map (sym => nme.defaultGetterToMethod(sym.name))
- defaultMethodNames.distinct foreach { name =>
+ defaultMethodNames.toList.distinct foreach { name =>
val methods = clazz.info.findMember(name, 0L, METHOD, false).alternatives
val haveDefaults = methods filter (sym => sym.hasParamWhich(_.hasDefault) && !nme.isProtectedAccessorName(sym.name))
@@ -628,7 +628,7 @@ abstract class RefChecks extends InfoTransform with reflect.internal.transform.R
matchingArity match {
// So far so good: only one candidate method
- case concrete :: Nil =>
+ case Scope(concrete) =>
val mismatches = abstractParams zip concrete.tpe.paramTypes filterNot { case (x, y) => x =:= y }
mismatches match {
// Only one mismatched parameter: say something useful.
diff --git a/src/library/scala/reflect/base/Base.scala b/src/library/scala/reflect/base/Base.scala
index 53854f160d..ddb502fd44 100644
--- a/src/library/scala/reflect/base/Base.scala
+++ b/src/library/scala/reflect/base/Base.scala
@@ -170,12 +170,17 @@ class Base extends Universe { self =>
object BoundedWildcardType extends BoundedWildcardTypeExtractor
implicit val BoundedWildcardTypeTag = ClassTag[BoundedWildcardType](classOf[BoundedWildcardType])
- type Scope = Iterable[Symbol]
+ class Scope(elems: Iterable[Symbol]) extends ScopeBase with MemberScopeBase {
+ def iterator = elems.iterator
+ def sorted = elems.toList
+ }
+ type MemberScope = Scope
implicit val ScopeTag = ClassTag[Scope](classOf[Scope])
+ implicit val MemberScopeTag = ClassTag[MemberScope](classOf[MemberScope])
- def newScope = newScopeWith()
- def newNestedScope(outer: Iterable[Symbol]) = newScope
- def newScopeWith(elems: Symbol*): Scope = elems
+ def newScope: Scope = newScopeWith()
+ def newNestedScope(outer: Scope): Scope = newScope
+ def newScopeWith(elems: Symbol*): Scope = new Scope(elems)
abstract class Name(str: String) extends NameBase {
override def toString = str
diff --git a/src/library/scala/reflect/base/Scopes.scala b/src/library/scala/reflect/base/Scopes.scala
index a5db01c0ce..a388fdc392 100644
--- a/src/library/scala/reflect/base/Scopes.scala
+++ b/src/library/scala/reflect/base/Scopes.scala
@@ -3,13 +3,33 @@ package base
trait Scopes { self: Universe =>
- type Scope >: Null <: Iterable[Symbol]
+ type Scope >: Null <: ScopeBase
+
+ /** The base API that all scopes support */
+ trait ScopeBase extends Iterable[Symbol]
/** A tag that preserves the identity of the `Scope` abstract type from erasure.
* Can be used for pattern matching, instance tests, serialization and likes.
*/
implicit val ScopeTag: ClassTag[Scope]
+ type MemberScope >: Null <: Scope with MemberScopeBase
+
+ /** The base API that all member scopes support */
+ trait MemberScopeBase extends ScopeBase {
+ /** Sorts the symbols included in this scope so that:
+ * 1) Symbols appear the linearization order of their owners.
+ * 2) Symbols with the same owner appear in reverse order of their declarations.
+ * 3) Synthetic members (e.g. getters/setters for vals/vars) might appear in arbitrary order.
+ */
+ def sorted: List[Symbol]
+ }
+
+ /** A tag that preserves the identity of the `MemberScope` abstract type from erasure.
+ * Can be used for pattern matching, instance tests, serialization and likes.
+ */
+ implicit val MemberScopeTag: ClassTag[MemberScope]
+
/** Create a new scope */
def newScope: Scope
diff --git a/src/reflect/scala/reflect/api/Types.scala b/src/reflect/scala/reflect/api/Types.scala
index 01de5fa9a7..33248fcbee 100644
--- a/src/reflect/scala/reflect/api/Types.scala
+++ b/src/reflect/scala/reflect/api/Types.scala
@@ -24,33 +24,26 @@ trait Types extends base.Types { self: Universe =>
*/
def declaration(name: Name): Symbol
- /** The collection of declarations in this type
- * [Eugene++] why not List?
+ /** A `Scope` containing directly declared members of this type.
+ * Unlike `members` this method doesn't returns inherited members.
+ *
+ * Members in the returned scope might appear in arbitrary order.
+ * Use `declarations.sorted` to get an ordered list of members.
*/
- def declarations: Iterable[Symbol]
+ def declarations: MemberScope
/** The member with given name, either directly declared or inherited,
* an OverloadedSymbol if several exist, NoSymbol if none exist.
*/
def member(name: Name): Symbol
- /** The non-private member with given name, either directly declared or inherited,
- * an OverloadedSymbol if several exist, NoSymbol if none exist.
- */
- def nonPrivateMember(name: Name): Symbol
-
- /** An iterable containing all members of this type (directly declared or inherited)
- * Members appear in the linearization order of their owners.
- * Members with the same owner appear in reverse order of their declarations.
- * [Eugene++] the order needs to be reversed back, at least in the public API
- */
- def members: Iterable[Symbol]
-
- /** An iterable containing all non-private members of this type (directly declared or inherited)
- * Members appear in the linearization order of their owners.
- * Members with the same owner appear in reverse order of their declarations.
+ /** A `Scope` containing all members of this type (directly declared or inherited).
+ * Unlike `declarations` this method also returns inherited members.
+ *
+ * Members in the returned scope might appear in arbitrary order.
+ * Use `declarations.sorted` to get an ordered list of members.
*/
- def nonPrivateMembers: Iterable[Symbol]
+ def members: MemberScope
/** Substitute symbols in `to` for corresponding occurrences of references to
* symbols `from` in this type.
diff --git a/src/reflect/scala/reflect/internal/Scopes.scala b/src/reflect/scala/reflect/internal/Scopes.scala
index 89e3c52de6..ed390b5a3b 100644
--- a/src/reflect/scala/reflect/internal/Scopes.scala
+++ b/src/reflect/scala/reflect/internal/Scopes.scala
@@ -41,9 +41,9 @@ trait Scopes extends api.Scopes { self: SymbolTable =>
* This is necessary because when run from reflection every scope needs to have a
* SynchronizedScope as mixin.
*/
- class Scope protected[Scopes] (initElems: ScopeEntry = null, initFingerPrints: Long = 0L) extends Iterable[Symbol] {
-
- /** A bitset containing the last 6 bits of the start value of every name
+ class Scope protected[Scopes] (initElems: ScopeEntry = null, initFingerPrints: Long = 0L) extends ScopeBase with MemberScopeBase {
+
+ /** A bitset containing the last 6 bits of the start value of every name
* stored in this scope.
*/
var fingerPrints: Long = initFingerPrints
@@ -118,10 +118,10 @@ trait Scopes extends api.Scopes { self: SymbolTable =>
*
* @param sym ...
*/
- def enter[T <: Symbol](sym: T): T = {
+ def enter[T <: Symbol](sym: T): T = {
fingerPrints |= sym.name.fingerPrint
- enterEntry(newScopeEntry(sym, this))
- sym
+ enterEntry(newScopeEntry(sym, this))
+ sym
}
/** enter a symbol, asserting that no symbol with same name exists in scope
@@ -282,6 +282,10 @@ trait Scopes extends api.Scopes { self: SymbolTable =>
elemsCache
}
+ /** Vanilla scope - symbols are stored in declaration order.
+ */
+ def sorted: List[Symbol] = toList
+
/** Return the nesting level of this scope, i.e. the number of times this scope
* was nested in another */
def nestingLevel = nestinglevel
@@ -324,14 +328,46 @@ trait Scopes extends api.Scopes { self: SymbolTable =>
toList.map(_.defString).mkString(start, sep, end)
override def toString(): String = mkString("Scope{\n ", ";\n ", "\n}")
-
}
implicit val ScopeTag = ClassTag[Scope](classOf[Scope])
+ type MemberScope = Scope
+
+ implicit val MemberScopeTag = ClassTag[MemberScope](classOf[MemberScope])
+
/** Create a new scope */
def newScope: Scope = new Scope()
+ /** Create a new scope to be used in `findMembers`.
+ *
+ * But why do we need a special scope for `findMembers`?
+ * Let me tell you a story.
+ *
+ * `findMembers` creates a synthetic scope and then iterates over
+ * base classes in linearization order, and for every scrutinized class
+ * iterates over `decls`, the collection of symbols declared in that class.
+ * Declarations that fit the filter get appended to the created scope.
+ *
+ * The problem is that `decls` returns a Scope, and to iterate a scope performantly
+ * one needs to go from its end to its beginning.
+ *
+ * Hence the `findMembers` scope is populated in a wicked order:
+ * symbols that belong to the same declaring class come in reverse order of their declaration,
+ * however, the scope itself is ordered w.r.t the linearization of the target type.
+ *
+ * Once `members` became a public API, this has been confusing countless numbers of users.
+ * Therefore we introduce a special flavor of scopes to accommodate this quirk of `findMembers`
+ */
+ private[scala] def newFindMemberScope: Scope = new Scope() {
+ override def sorted = {
+ val members = toList
+ val owners = members.map(_.owner).distinct
+ val grouped = members groupBy (_.owner)
+ owners.flatMap(owner => grouped(owner).reverse)
+ }
+ }
+
/** Create a new scope nested in another one with which it shares its elements */
def newNestedScope(outer: Scope): Scope = new Scope(outer)
diff --git a/src/reflect/scala/reflect/internal/Symbols.scala b/src/reflect/scala/reflect/internal/Symbols.scala
index e6a9cb46c6..05ead8d1ac 100644
--- a/src/reflect/scala/reflect/internal/Symbols.scala
+++ b/src/reflect/scala/reflect/internal/Symbols.scala
@@ -2890,7 +2890,7 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
private[this] var typeOfThisCache: Type = _
private[this] var typeOfThisPeriod = NoPeriod
- private var implicitMembersCacheValue: List[Symbol] = Nil
+ private var implicitMembersCacheValue: Scope = EmptyScope
private var implicitMembersCacheKey1: Type = NoType
private var implicitMembersCacheKey2: ScopeEntry = null
@@ -2909,7 +2909,7 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
typeOfThisCache
}
- def implicitMembers: List[Symbol] = {
+ def implicitMembers: Scope = {
val tp = info
if ((implicitMembersCacheKey1 ne tp) || (implicitMembersCacheKey2 ne tp.decls.elems)) {
// Skip a package object class, because the members are also in
diff --git a/src/reflect/scala/reflect/internal/Types.scala b/src/reflect/scala/reflect/internal/Types.scala
index 8972dfa828..1386cca42f 100644
--- a/src/reflect/scala/reflect/internal/Types.scala
+++ b/src/reflect/scala/reflect/internal/Types.scala
@@ -612,21 +612,21 @@ trait Types extends api.Types { self: SymbolTable =>
* Members appear in linearization order of their owners.
* Members with the same owner appear in reverse order of their declarations.
*/
- def members: List[Symbol] = membersBasedOnFlags(0, 0)
+ def members: Scope = membersBasedOnFlags(0, 0)
/** A list of all non-private members of this type (defined or inherited) */
- def nonPrivateMembers: List[Symbol] = membersBasedOnFlags(BridgeAndPrivateFlags, 0)
+ def nonPrivateMembers: Scope = membersBasedOnFlags(BridgeAndPrivateFlags, 0)
/** A list of all non-private members of this type (defined or inherited),
* admitting members with given flags `admit`
*/
- def nonPrivateMembersAdmitting(admit: Long): List[Symbol] = membersBasedOnFlags(BridgeAndPrivateFlags & ~admit, 0)
+ def nonPrivateMembersAdmitting(admit: Long): Scope = membersBasedOnFlags(BridgeAndPrivateFlags & ~admit, 0)
/** A list of all implicit symbols of this type (defined or inherited) */
- def implicitMembers: List[Symbol] = membersBasedOnFlags(BridgeFlags, IMPLICIT)
+ def implicitMembers: Scope = membersBasedOnFlags(BridgeFlags, IMPLICIT)
/** A list of all deferred symbols of this type (defined or inherited) */
- def deferredMembers: List[Symbol] = membersBasedOnFlags(BridgeFlags, DEFERRED)
+ def deferredMembers: Scope = membersBasedOnFlags(BridgeFlags, DEFERRED)
/** The member with given name,
* an OverloadedSymbol if several exist, NoSymbol if none exist */
@@ -642,12 +642,12 @@ trait Types extends api.Types { self: SymbolTable =>
/** All members with the given flags, excluding bridges.
*/
- def membersWithFlags(requiredFlags: Long): List[Symbol] =
+ def membersWithFlags(requiredFlags: Long): Scope =
membersBasedOnFlags(BridgeFlags, requiredFlags)
/** All non-private members with the given flags, excluding bridges.
*/
- def nonPrivateMembersWithFlags(requiredFlags: Long): List[Symbol] =
+ def nonPrivateMembersWithFlags(requiredFlags: Long): Scope =
membersBasedOnFlags(BridgeAndPrivateFlags, requiredFlags)
/** The non-private member with given name, admitting members with given flags `admit`.
@@ -668,7 +668,7 @@ trait Types extends api.Types { self: SymbolTable =>
/** Members excluding and requiring the given flags.
* Note: unfortunately it doesn't work to exclude DEFERRED this way.
*/
- def membersBasedOnFlags(excludedFlags: Long, requiredFlags: Long): List[Symbol] =
+ def membersBasedOnFlags(excludedFlags: Long, requiredFlags: Long): Scope =
findMembers(excludedFlags, requiredFlags)
// findMember(nme.ANYNAME, excludedFlags, requiredFlags, false).alternatives
@@ -1020,7 +1020,7 @@ trait Types extends api.Types { self: SymbolTable =>
else (baseClasses.head.newOverloaded(this, alts))
}
- def findMembers(excludedFlags: Long, requiredFlags: Long): List[Symbol] = {
+ def findMembers(excludedFlags: Long, requiredFlags: Long): Scope = {
// if this type contains type variables, put them to sleep for a while -- don't just wipe them out by
// replacing them by the corresponding type parameter, as that messes up (e.g.) type variables in type refinements
// without this, the matchesType call would lead to type variables on both sides
@@ -1054,7 +1054,7 @@ trait Types extends api.Types { self: SymbolTable =>
(bcs eq bcs0) ||
(flags & PrivateLocal) != PrivateLocal ||
(bcs0.head.hasTransOwner(bcs.head)))) {
- if (members eq null) members = newScope
+ if (members eq null) members = newFindMemberScope
var others: ScopeEntry = members.lookupEntry(sym.name)
var symtpe: Type = null
while ((others ne null) && {
@@ -1083,7 +1083,7 @@ trait Types extends api.Types { self: SymbolTable =>
} // while (continue)
Statistics.popTimer(typeOpsStack, start)
if (suspension ne null) suspension foreach (_.suspended = false)
- if (members eq null) Nil else members.toList
+ if (members eq null) EmptyScope else members
}
/**
diff --git a/src/reflect/scala/reflect/runtime/SynchronizedSymbols.scala b/src/reflect/scala/reflect/runtime/SynchronizedSymbols.scala
index 3b28ddf42c..6a3501b1dd 100644
--- a/src/reflect/scala/reflect/runtime/SynchronizedSymbols.scala
+++ b/src/reflect/scala/reflect/runtime/SynchronizedSymbols.scala
@@ -134,7 +134,7 @@ trait SynchronizedSymbols extends internal.Symbols { self: SymbolTable =>
override def sourceModule = synchronized { super.sourceModule }
// [Eugene++ to Martin] doesn't override anything. no longer necessary?
// def sourceModule_=(module: ModuleSymbol) = synchronized { super.sourceModule_=(module) }
- override def implicitMembers: List[Symbol] = synchronized { super.implicitMembers }
+ override def implicitMembers: Scope = synchronized { super.implicitMembers }
}
}
diff --git a/test/files/run/reflection-simple.scala b/test/files/run/reflection-simple.scala
deleted file mode 100644
index ec34b71cec..0000000000
--- a/test/files/run/reflection-simple.scala
+++ /dev/null
@@ -1,12 +0,0 @@
-// a.scala
-// Wed May 2 01:01:22 PDT 2012
-
-object Test {
- def main(args: Array[String]) {
- System.out.println("Running")
- case class Foo(a: Int, b: Int, c: Int)
- import scala.reflect.runtime.{currentMirror => cm}
- val props = cm.classSymbol(classOf[Foo]).typeSignature.members.filter(_.isTerm).map(_.toString)
- props.toList.sorted foreach System.out.println
- }
-}
diff --git a/test/files/run/reflection-sorted-decls.check b/test/files/run/reflection-sorted-decls.check
new file mode 100644
index 0000000000..9a9832a683
--- /dev/null
+++ b/test/files/run/reflection-sorted-decls.check
@@ -0,0 +1,7 @@
+value a
+value b
+value c
+method c
+method b
+method a
+constructor Foo$1
diff --git a/test/files/run/reflection-sorted-decls.scala b/test/files/run/reflection-sorted-decls.scala
new file mode 100644
index 0000000000..242f17d9bb
--- /dev/null
+++ b/test/files/run/reflection-sorted-decls.scala
@@ -0,0 +1,8 @@
+object Test {
+ def main(args: Array[String]) {
+ class Foo(val a: Int, val b: Int, val c: Int)
+ import scala.reflect.runtime.{currentMirror => cm}
+ val decls = cm.classSymbol(classOf[Foo]).typeSignature.declarations
+ decls.sorted.toList foreach System.out.println
+ }
+}
diff --git a/test/files/run/reflection-simple.check b/test/files/run/reflection-sorted-members.check
index 671d9d2716..d58b691c42 100644
--- a/test/files/run/reflection-simple.check
+++ b/test/files/run/reflection-sorted-members.check
@@ -1,45 +1,34 @@
-Running
-constructor Foo$3
-constructor Object
-method !=
-method !=
-method ##
-method $asInstanceOf
-method $init$
-method $isInstanceOf
-method ==
-method ==
-method _1
-method _2
-method _3
-method a
-method asInstanceOf
-method b
-method c
-method canEqual
-method clone
-method copy
-method copy$default$1
-method copy$default$2
-method copy$default$3
-method eq
-method equals
-method finalize
-method getClass
-method hashCode
-method isInstanceOf
-method ne
-method notify
-method notifyAll
-method productArity
-method productElement
-method productIterator
-method productPrefix
-method synchronized
-method toString
-method wait
-method wait
-method wait
-value a
-value b
-value c
+value a
+value b
+value c
+method c
+method b
+method a
+constructor Foo$1
+value x
+method x
+constructor Bar$1
+method finalize
+method wait
+method wait
+method wait
+method equals
+method toString
+method hashCode
+method getClass
+method clone
+method notify
+method notifyAll
+constructor Object
+method eq
+method ne
+method ==
+method !=
+method ##
+method synchronized
+method $isInstanceOf
+method $asInstanceOf
+method ==
+method !=
+method isInstanceOf
+method asInstanceOf
diff --git a/test/files/run/reflection-sorted-members.scala b/test/files/run/reflection-sorted-members.scala
new file mode 100644
index 0000000000..9980d79999
--- /dev/null
+++ b/test/files/run/reflection-sorted-members.scala
@@ -0,0 +1,11 @@
+object Test {
+ def main(args: Array[String]) {
+ trait T1 { def a: Int; def c: Int }
+ trait T2 { def a: Int; def b: Int }
+ class Bar(val x: Int)
+ class Foo(val a: Int, val b: Int, val c: Int) extends Bar(a + b + c) with T1 with T2
+ import scala.reflect.runtime.{currentMirror => cm}
+ val members = cm.classSymbol(classOf[Foo]).typeSignature.members
+ members.sorted.toList foreach System.out.println
+ }
+}