diff options
-rw-r--r-- | compiler/plugins/locals.nim | 23 | ||||
-rw-r--r-- | tests/misc/tlocals.nim | 36 |
2 files changed, 46 insertions, 13 deletions
diff --git a/compiler/plugins/locals.nim b/compiler/plugins/locals.nim index 08d836f7d..73f6eaa19 100644 --- a/compiler/plugins/locals.nim +++ b/compiler/plugins/locals.nim @@ -17,25 +17,24 @@ proc semLocals*(c: PContext, n: PNode): PNode = var tupleType = newTypeS(tyTuple, c) result = newNodeIT(nkPar, n.info, tupleType) tupleType.n = newNodeI(nkRecList, n.info) + let owner = getCurrOwner(c) # for now we skip openarrays ... for scope in walkScopes(c.currentScope): if scope == c.topLevelScope: break for it in items(scope.symbols): - # XXX parameters' owners are wrong for generics; this caused some pain - # for closures too; we should finally fix it. - #if it.owner != c.p.owner: return result if it.kind in skLocalVars and it.typ.skipTypes({tyGenericInst, tyVar}).kind notin {tyVarargs, tyOpenArray, tyTypeDesc, tyStatic, tyUntyped, tyTyped, tyEmpty}: - var field = newSym(skField, it.name, getCurrOwner(c), n.info) - field.typ = it.typ.skipTypes({tyVar}) - field.position = counter - inc(counter) + if it.owner == owner: + var field = newSym(skField, it.name, owner, n.info) + field.typ = it.typ.skipTypes({tyVar}) + field.position = counter + inc(counter) - addSon(tupleType.n, newSymNode(field)) - addSonSkipIntLit(tupleType, field.typ) + addSon(tupleType.n, newSymNode(field)) + addSonSkipIntLit(tupleType, field.typ) - var a = newSymNode(it, result.info) - if it.typ.skipTypes({tyGenericInst}).kind == tyVar: a = newDeref(a) - result.add(a) + var a = newSymNode(it, result.info) + if it.typ.skipTypes({tyGenericInst}).kind == tyVar: a = newDeref(a) + result.add(a) diff --git a/tests/misc/tlocals.nim b/tests/misc/tlocals.nim index e6c73313d..ad9e7d032 100644 --- a/tests/misc/tlocals.nim +++ b/tests/misc/tlocals.nim @@ -1,5 +1,7 @@ discard """ - output: '''(x: "string here", a: 1)''' + output: '''(x: "string here", a: 1) +b is 5 +x is 12''' """ proc simple[T](a: T) = @@ -28,3 +30,35 @@ proc test(baz: int, qux: var int): int = var x1 = 456 discard test(123, x1) + +# bug #11958 +proc foo() = + var a = 5 + proc bar() {.nimcall.} = + var b = 5 + for k, v in fieldpairs(locals()): + echo k, " is ", v + + bar() +foo() + + +proc foo2() = + var a = 5 + proc bar2() {.nimcall.} = + for k, v in fieldpairs(locals()): + echo k, " is ", v + + bar2() +foo2() + + +proc foo3[T](y: T) = + var a = 5 + proc bar2[T](x: T) {.nimcall.} = + for k, v in fieldpairs(locals()): + echo k, " is ", v + + bar2(y) + +foo3(12) |