summary refs log tree commit diff stats
path: root/compiler/lookups.nim
diff options
context:
space:
mode:
authorClyybber <darkmine956@gmail.com>2020-08-27 15:50:59 +0200
committerGitHub <noreply@github.com>2020-08-27 15:50:59 +0200
commitfb58066b61b14f4a1d6cdb0f4a8f0a9ea4174d82 (patch)
treec6e573d9ac221c786ac9e0ca2cf0f186d87a6bbe /compiler/lookups.nim
parentd11933ad998fb0a3eb51bbefbaa53e583aaa3ac1 (diff)
downloadNim-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.nim22
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 =