summaryrefslogtreecommitdiff
path: root/src/reflect
diff options
context:
space:
mode:
authorLukas Rytz <lukas.rytz@gmail.com>2017-02-21 10:23:00 +0100
committerGitHub <noreply@github.com>2017-02-21 10:23:00 +0100
commitdabec1a262fafd26bf6976ac3f0b81445ddb5f29 (patch)
tree7e9b0c965db1b41bb74977d83f1e13a6a9033e70 /src/reflect
parent2f1e0c22ecd3b6e3886bd9bc94f27725e08324b8 (diff)
parent06eee798f581ffa21dc4a69974315a7c2bc7abe1 (diff)
downloadscala-dabec1a262fafd26bf6976ac3f0b81445ddb5f29.tar.gz
scala-dabec1a262fafd26bf6976ac3f0b81445ddb5f29.tar.bz2
scala-dabec1a262fafd26bf6976ac3f0b81445ddb5f29.zip
Merge pull request #5700 from retronym/ticket/10154-refactor
Refactor lookupCompanion
Diffstat (limited to 'src/reflect')
-rw-r--r--src/reflect/scala/reflect/internal/Scopes.scala33
1 files changed, 14 insertions, 19 deletions
diff --git a/src/reflect/scala/reflect/internal/Scopes.scala b/src/reflect/scala/reflect/internal/Scopes.scala
index 51fb31d36d..0435a2c1cf 100644
--- a/src/reflect/scala/reflect/internal/Scopes.scala
+++ b/src/reflect/scala/reflect/internal/Scopes.scala
@@ -291,25 +291,6 @@ trait Scopes extends api.Scopes { self: SymbolTable =>
null
}
- final def lookupCompanion(original: Symbol): Symbol = {
- lookupSymbolEntry(original) match {
- case null =>
- case entry =>
- var e = lookupEntry(original.name.companionName)
- while (e != null) {
- // 1) Must be owned by the same Scope, to ensure that in
- // `{ class C; { ...; object C } }`, the class is not seen as a companion of the object.
- // 2) Must be a class and module symbol, so that `{ class C; def C }` or `{ type T; object T }` are not companions.
- def isClassAndModule(sym1: Symbol, sym2: Symbol) = sym1.isClass && sym2.isModule
- if ((e.owner eq entry.owner) && (isClassAndModule(original, e.sym) || isClassAndModule(e.sym, original))) {
- return if (e.sym.isCoDefinedWith(original)) e.sym else NoSymbol
- }
- e = lookupNextEntry(e)
- }
- }
- NoSymbol
- }
-
/** lookup a symbol entry matching given name.
* @note from Martin: I believe this is a hotspot or will be one
* in future versions of the type system. I have reverted the previous
@@ -345,6 +326,20 @@ trait Scopes extends api.Scopes { self: SymbolTable =>
e
}
+ final def lookupNameInSameScopeAs(original: Symbol, companionName: Name): Symbol = {
+ lookupSymbolEntry(original) match {
+ case null =>
+ case entry =>
+ var e = lookupEntry(companionName)
+ while (e != null) {
+ if (e.owner eq entry.owner) return e.sym
+ e = lookupNextEntry(e)
+ }
+ }
+ NoSymbol
+ }
+
+
/** TODO - we can test this more efficiently than checking isSubScope
* in both directions. However the size test might be enough to quickly
* rule out most failures.