diff options
author | Lukas Rytz <lukas.rytz@gmail.com> | 2016-12-12 15:10:01 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-12 15:10:01 +0100 |
commit | d34e44e99488e4f91a677ddbc2e8ae6232273456 (patch) | |
tree | 6fa403cdd85cf273072662894a52083c3b86bc81 /src/compiler/scala/tools | |
parent | 623f0a72bad9513a154b4a6367c5e215adf769d0 (diff) | |
parent | 9502a061fa007ceb1d4e550fdb386a3645c67b1c (diff) | |
download | scala-d34e44e99488e4f91a677ddbc2e8ae6232273456.tar.gz scala-d34e44e99488e4f91a677ddbc2e8ae6232273456.tar.bz2 scala-d34e44e99488e4f91a677ddbc2e8ae6232273456.zip |
Merge pull request #5550 from retronym/ticket/3772
SI-3772 Fix detection of term-owned companions
Diffstat (limited to 'src/compiler/scala/tools')
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Contexts.scala | 21 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Namers.scala | 10 |
2 files changed, 26 insertions, 5 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala index 8f0625e58c..fde2f7bb03 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala @@ -1192,6 +1192,27 @@ trait Contexts { self: Analyzer => } res } + + final def lookupCompanionOf(original: Symbol): Symbol = { + lookupScopeEntry(original) match { + case null => NoSymbol + case entry => entry.owner.lookupCompanion(original) + } + } + + /** Search scopes in current and enclosing contexts for the definition of `symbol` */ + private def lookupScopeEntry(symbol: Symbol): ScopeEntry = { + var res: ScopeEntry = null + var ctx = this + while (res == null && ctx.outer != ctx) { + val s = ctx.scope lookupSymbolEntry symbol + if (s != null) + res = s + else + ctx = ctx.outer + } + res + } } //class Context /** A `Context` focussed on an `Import` tree */ diff --git a/src/compiler/scala/tools/nsc/typechecker/Namers.scala b/src/compiler/scala/tools/nsc/typechecker/Namers.scala index b445bc5837..395bda234b 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala @@ -220,7 +220,10 @@ trait Namers extends MethodSynthesis { private def inCurrentScope(m: Symbol): Boolean = { if (owner.isClass) owner == m.owner - else m.owner.isClass && context.scope == m.owner.info.decls + else context.scope.lookupSymbolEntry(m) match { + case null => false + case entry => entry.owner eq context.scope + } } /** Enter symbol into context's scope and return symbol itself */ @@ -1953,10 +1956,7 @@ trait Namers extends MethodSynthesis { // use the lower-level scan through the current Context as a fall back. if (!currentRun.compiles(owner)) owner.initialize original.companionSymbol orElse { - ctx.lookup(original.name.companionName, owner).suchThat(sym => - (original.isTerm || sym.hasModuleFlag) && - (sym isCoDefinedWith original) - ) + ctx.lookupCompanionOf(original) } } |