This commit is contained in:
Andreas Rumpf 2019-08-23 18:58:55 +02:00 • committed by GitHub
commit fbb2763204
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 13 deletions

View file

@ -17,18 +17,17 @@ proc semLocals*(c: PContext, n: PNode): PNode =
var tupleType = newTypeS(tyTuple, c) var tupleType = newTypeS(tyTuple, c)
result = newNodeIT(nkPar, n.info, tupleType) result = newNodeIT(nkPar, n.info, tupleType)
tupleType.n = newNodeI(nkRecList, n.info) tupleType.n = newNodeI(nkRecList, n.info)
let owner = getCurrOwner(c)
# for now we skip openarrays ... # for now we skip openarrays ...
for scope in walkScopes(c.currentScope): for scope in walkScopes(c.currentScope):
if scope == c.topLevelScope: break if scope == c.topLevelScope: break
for it in items(scope.symbols): 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 if it.kind in skLocalVars and
it.typ.skipTypes({tyGenericInst, tyVar}).kind notin it.typ.skipTypes({tyGenericInst, tyVar}).kind notin
{tyVarargs, tyOpenArray, tyTypeDesc, tyStatic, tyUntyped, tyTyped, tyEmpty}: {tyVarargs, tyOpenArray, tyTypeDesc, tyStatic, tyUntyped, tyTyped, tyEmpty}:
var field = newSym(skField, it.name, getCurrOwner(c), n.info) if it.owner == owner:
var field = newSym(skField, it.name, owner, n.info)
field.typ = it.typ.skipTypes({tyVar}) field.typ = it.typ.skipTypes({tyVar})
field.position = counter field.position = counter
inc(counter) inc(counter)

View file

@ -1,5 +1,7 @@
discard """ discard """
output: '''(x: "string here", a: 1)''' output: '''(x: "string here", a: 1)
b is 5
x is 12'''
""" """
proc simple[T](a: T) = proc simple[T](a: T) =
@ -28,3 +30,35 @@ proc test(baz: int, qux: var int): int =
var x1 = 456 var x1 = 456
discard test(123, x1) 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)