mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-15 15:44:14 +00:00
Merge pull request #11159 from JasperJenkins/const-named-tuple-unpack
Const named tuple unpacking
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
discard """
|
||||
action: run
|
||||
disabled: true
|
||||
"""
|
||||
|
||||
block:
|
||||
|
||||
@@ -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