diff options
author | Clyybber <darkmine956@gmail.com> | 2020-08-27 15:50:59 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-27 15:50:59 +0200 |
commit | fb58066b61b14f4a1d6cdb0f4a8f0a9ea4174d82 (patch) | |
tree | c6e573d9ac221c786ac9e0ca2cf0f186d87a6bbe /compiler/lookups.nim | |
parent | d11933ad998fb0a3eb51bbefbaa53e583aaa3ac1 (diff) | |
download | Nim-fb58066b61b14f4a1d6cdb0f4a8f0a9ea4174d82.tar.gz |
Fix #5691 (#15158)
* Fix #5691 * Cleanup and thoughts * Use scope approach * Seperate defined/declared/declaredInScope magics * Fix declaredInScope * Update spec accordingly
Diffstat (limited to 'compiler/lookups.nim')
-rw-r--r-- | compiler/lookups.nim | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/compiler/lookups.nim b/compiler/lookups.nim index a3a2bf49c..c0db25950 100644 --- a/compiler/lookups.nim +++ b/compiler/lookups.nim @@ -93,6 +93,11 @@ proc skipAlias*(s: PSym; n: PNode; conf: ConfigRef): PSym = proc localSearchInScope*(c: PContext, s: PIdent): PSym = result = strTableGet(c.currentScope.symbols, s) + var shadow = c.currentScope + while result == nil and shadow.parent != nil and shadow.depthLevel == shadow.parent.depthLevel: + # We are in a shadow scope, check in the parent too + result = strTableGet(shadow.parent.symbols, s) + shadow = shadow.parent proc searchInScopes*(c: PContext, s: PIdent): PSym = for scope in walkScopes(c.currentScope): @@ -231,6 +236,23 @@ proc addInterfaceOverloadableSymAt*(c: PContext, scope: PScope, sym: PSym) = addOverloadableSymAt(c, scope, sym) addInterfaceDeclAux(c, sym) +proc openShadowScope*(c: PContext) = + c.currentScope = PScope(parent: c.currentScope, + symbols: newStrTable(), + depthLevel: c.scopeDepth) + +proc closeShadowScope*(c: PContext) = + c.closeScope + +proc mergeShadowScope*(c: PContext) = + let shadowScope = c.currentScope + c.rawCloseScope + for sym in shadowScope.symbols: + if sym.kind in OverloadableSyms: + c.addInterfaceOverloadableSymAt(c.currentScope, sym) + else: + c.addInterfaceDecl(sym) + when defined(nimfix): # when we cannot find the identifier, retry with a changed identifier: proc altSpelling(x: PIdent): PIdent = |