summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
diff options
context:
space:
mode:
authorLukas Rytz <lukas.rytz@gmail.com>2016-12-12 15:10:01 +0100
committerGitHub <noreply@github.com>2016-12-12 15:10:01 +0100
commitd34e44e99488e4f91a677ddbc2e8ae6232273456 (patch)
tree6fa403cdd85cf273072662894a52083c3b86bc81 /src/compiler/scala/tools/nsc/typechecker/Contexts.scala
parent623f0a72bad9513a154b4a6367c5e215adf769d0 (diff)
parent9502a061fa007ceb1d4e550fdb386a3645c67b1c (diff)
downloadscala-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/nsc/typechecker/Contexts.scala')
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Contexts.scala21
1 files changed, 21 insertions, 0 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 */