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/reflect/scala/reflect | |
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/reflect/scala/reflect')
-rw-r--r-- | src/reflect/scala/reflect/internal/Scopes.scala | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/reflect/scala/reflect/internal/Scopes.scala b/src/reflect/scala/reflect/internal/Scopes.scala index a7bb127506..32ce02bdd6 100644 --- a/src/reflect/scala/reflect/internal/Scopes.scala +++ b/src/reflect/scala/reflect/internal/Scopes.scala @@ -282,6 +282,34 @@ trait Scopes extends api.Scopes { self: SymbolTable => } } + final def lookupSymbolEntry(sym: Symbol): ScopeEntry = { + var e = lookupEntry(sym.name) + while (e ne null) { + if (e.sym == sym) return e + e = lookupNextEntry(e) + } + 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 comaniopn 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 |