diff options
author | Clyybber <darkmine956@gmail.com> | 2020-09-22 18:24:13 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-22 18:24:13 +0200 |
commit | 4b9eea2fcc5d030393ca9020fbbee33fcb48d41a (patch) | |
tree | 4024e3074ebbaf636ee0f00415f9f0861c4bf522 /compiler/lookups.nim | |
parent | 11c377c1149a23657a7f0dd897866cb550ade8d1 (diff) | |
download | Nim-4b9eea2fcc5d030393ca9020fbbee33fcb48d41a.tar.gz |
Fix forward declarations in shadow scope contexts (#15386)
* Fix forward declarations in shadow scope contexts * Add testcase for #15385 * Less empty lines * Fix tests * Inline isShadowScope * Add original testcase (with reduced amount of iterations) * Add testcase without forward decl
Diffstat (limited to 'compiler/lookups.nim')
-rw-r--r-- | compiler/lookups.nim | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/compiler/lookups.nim b/compiler/lookups.nim index c0db25950..744f77cf8 100644 --- a/compiler/lookups.nim +++ b/compiler/lookups.nim @@ -91,13 +91,15 @@ proc skipAlias*(s: PSym; n: PNode; conf: ConfigRef): PSym = message(conf, n.info, warnDeprecated, "use " & result.name.s & " instead; " & s.name.s & " is deprecated") +proc isShadowScope*(s: PScope): bool {.inline.} = s.parent != nil and s.parent.depthLevel == s.depthLevel + 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: + var scope = c.currentScope + result = strTableGet(scope.symbols, s) + while result == nil and scope.isShadowScope: # We are in a shadow scope, check in the parent too - result = strTableGet(shadow.parent.symbols, s) - shadow = shadow.parent + scope = scope.parent + result = strTableGet(scope.symbols, s) proc searchInScopes*(c: PContext, s: PIdent): PSym = for scope in walkScopes(c.currentScope): |