mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-05 04:27:44 +00:00
newLit emty seq fix (#6091)
* the type of the empty seq is still the correct type * updated test
This commit is contained in:
committed by
Andreas Rumpf
parent
03e0aa37e3
commit
52cab78ae5
@@ -527,10 +527,17 @@ proc newLit*[N,T](arg: array[N,T]): NimNode {.compileTime.} =
|
||||
result.add newLit(x)
|
||||
|
||||
proc newLit*[T](arg: seq[T]): NimNode {.compileTime.} =
|
||||
result = nnkBracket.newTree
|
||||
var bracket = nnkBracket.newTree
|
||||
for x in arg:
|
||||
result.add newLit(x)
|
||||
result = nnkPrefix.newTree(bindSym"@", result)
|
||||
bracket.add newLit(x)
|
||||
|
||||
result = nnkCall.newTree(
|
||||
nnkBracketExpr.newTree(
|
||||
nnkAccQuoted.newTree( bindSym"@" ),
|
||||
getTypeInst( bindSym"T" )
|
||||
),
|
||||
bracket
|
||||
)
|
||||
|
||||
proc newLit*(arg: tuple): NimNode {.compileTime.} =
|
||||
result = nnkPar.newTree
|
||||
|
||||
@@ -138,3 +138,12 @@ macro test_newLit_ComposedType: untyped =
|
||||
result = newLit(ct)
|
||||
|
||||
doAssert test_newLit_ComposedType == ComposedType(mt: MyType(a: 123, b:"abc"), arr: [1,2,3,4], data: @[1.byte, 3, 7, 127])
|
||||
|
||||
macro test_newLit_empty_seq_string: untyped =
|
||||
var strSeq = newSeq[string](0)
|
||||
result = newLit(strSeq)
|
||||
|
||||
block:
|
||||
# x needs to be of type seq[string]
|
||||
var x = test_newLit_empty_seq_string
|
||||
x.add("xyz")
|
||||
|
||||
Reference in New Issue
Block a user