diff options
author | LemonBoy <thatlemon@gmail.com> | 2018-09-21 22:35:54 +0200 |
---|---|---|
committer | LemonBoy <thatlemon@gmail.com> | 2018-09-21 22:35:54 +0200 |
commit | e07ab06f0a59e0863855cfbd806ae0b2dcf644a6 (patch) | |
tree | 1ad5dedf95ad5345ccb9187122d7aa2fa6116dcb | |
parent | 6b5e2adfd08796eb73dbec479f3e40b22a366c98 (diff) | |
download | Nim-e07ab06f0a59e0863855cfbd806ae0b2dcf644a6.tar.gz |
Fix locals() interaction with generic types
Follow the same logic as semTupleFieldsConstr and only skip skVar since we're gonna add a nkDefer anyway. Fixes #8985
-rw-r--r-- | compiler/plugins/locals.nim | 2 | ||||
-rw-r--r-- | tests/misc/tlocals.nim | 19 |
2 files changed, 20 insertions, 1 deletions
diff --git a/compiler/plugins/locals.nim b/compiler/plugins/locals.nim index 0048ff985..4dd3e8f9c 100644 --- a/compiler/plugins/locals.nim +++ b/compiler/plugins/locals.nim @@ -29,7 +29,7 @@ proc semLocals*(c: PContext, n: PNode): PNode = {tyVarargs, tyOpenArray, tyTypeDesc, tyStatic, tyExpr, tyStmt, tyEmpty}: var field = newSym(skField, it.name, getCurrOwner(c), n.info) - field.typ = it.typ.skipTypes({tyGenericInst, tyVar}) + field.typ = it.typ.skipTypes({tyVar}) field.position = counter inc(counter) diff --git a/tests/misc/tlocals.nim b/tests/misc/tlocals.nim index 09b7432f5..e6c73313d 100644 --- a/tests/misc/tlocals.nim +++ b/tests/misc/tlocals.nim @@ -9,3 +9,22 @@ proc simple[T](a: T) = simple(1) +type Foo2[T]=object + a2: T + +proc numFields*(T: typedesc[tuple|object]): int= + var t:T + for _ in t.fields: inc result + +proc test(baz: int, qux: var int): int = + var foo: Foo2[int] + let bar = "abc" + let c1 = locals() + doAssert numFields(c1.foo.type) == 1 + doAssert c1.bar == "abc" + doAssert c1.baz == 123 + doAssert c1.result == 0 + doAssert c1.qux == 456 + +var x1 = 456 +discard test(123, x1) |