mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-21 14:55:24 +00:00
const named tuple unpacking
This commit is contained in:
@@ -701,7 +701,7 @@ proc getConstExpr(m: PSym, n: PNode; g: ModuleGraph): PNode =
|
||||
for i in countup(0, sonsLen(n) - 1):
|
||||
var a = getConstExpr(m, n.sons[i].sons[1], g)
|
||||
if a == nil: return nil
|
||||
result.sons[i].sons[1] = a
|
||||
result.sons[i] = a
|
||||
else:
|
||||
for i in countup(0, sonsLen(n) - 1):
|
||||
var a = getConstExpr(m, n.sons[i], g)
|
||||
|
||||
@@ -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 =
|
||||
|
||||
Reference in New Issue
Block a user