diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2019-05-08 17:50:41 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-08 17:50:41 +0200 |
commit | cd79c6f5323f70a1f3783cd8f0f17f47ed523fed (patch) | |
tree | ca3dbdaa0e9cba9d15a0505b5b9b5fbff8db03c8 | |
parent | 65b6250e59b8db6a54e01ba3e443c9ee0add6e48 (diff) | |
parent | 1f207df7aef7dd469a998a4522891b25eab4c9df (diff) | |
download | Nim-cd79c6f5323f70a1f3783cd8f0f17f47ed523fed.tar.gz |
Merge pull request #11159 from JasperJenkins/const-named-tuple-unpack
Const named tuple unpacking
-rw-r--r-- | compiler/semstmts.nim | 3 | ||||
-rw-r--r-- | tests/tuples/t9177.nim | 1 | ||||
-rw-r--r-- | tests/tuples/ttuples_various.nim | 21 |
3 files changed, 23 insertions, 2 deletions
diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index 1cf8e7ab2..6a92e9221 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -641,7 +641,8 @@ proc semConst(c: PContext, n: PNode): PNode = addSon(b, copyTree(def)) else: setVarType(c, v, typ.sons[j]) - v.ast = def[j] + v.ast = if def[j].kind != nkExprColonExpr: def[j] + else: def[j].sons[1] b.sons[j] = newSymNode(v) addSon(result,b) dec c.inStaticContext diff --git a/tests/tuples/t9177.nim b/tests/tuples/t9177.nim index d5768b703..e6dd0cb1d 100644 --- a/tests/tuples/t9177.nim +++ b/tests/tuples/t9177.nim @@ -1,6 +1,5 @@ discard """ action: run - disabled: true """ block: diff --git a/tests/tuples/ttuples_various.nim b/tests/tuples/ttuples_various.nim index 94a2f3ff0..dc060da1e 100644 --- a/tests/tuples/ttuples_various.nim +++ b/tests/tuples/ttuples_various.nim @@ -81,6 +81,27 @@ block unpack_const: doAssert z == 6 +# bug #10724 +block unpack_const_named: + const (a, ) = (x: 1, ) + doAssert a == 1 + + const (b, c) = (x: 2, y: 3) + doAssert b == 2 + doAssert c == 3 + + const (d, e, f) = (x: 4, y: 5, z: 6) + doAssert d == 4 + doAssert e == 5 + doAssert f == 6 + +block const_named: + const x = block: + (a: 1, b: 2, c: 3) + doAssert x.a == 1 + doAssert x.b == 2 + doAssert x.c == 3 + block tuple_subscript: proc`[]` (t: tuple, key: string): string = |