add legacy workaround; improve test so that it actually tests for the bugfix
This commit is contained in:
parent
408518c9fe
commit
9c42ae91b7
4 changed files with 14 additions and 35 deletions
|
|
@ -112,6 +112,7 @@
|
||||||
- new proc `heapqueue.find[T](heap: HeapQueue[T], x: T): int` to get index of element ``x``.
|
- new proc `heapqueue.find[T](heap: HeapQueue[T], x: T): int` to get index of element ``x``.
|
||||||
- Add `rstgen.rstToLatex` convenience proc for `renderRstToOut` and `initRstGenerator` with `outLatex` output.
|
- Add `rstgen.rstToLatex` convenience proc for `renderRstToOut` and `initRstGenerator` with `outLatex` output.
|
||||||
- Add `os.normalizeExe`, eg: `koch` => `./koch`.
|
- Add `os.normalizeExe`, eg: `koch` => `./koch`.
|
||||||
|
- `macros.newLit` now preserves named vs unnamed tuples; use `-d:nimHasWorkaround14720` to keep old behavior
|
||||||
|
|
||||||
|
|
||||||
## Language changes
|
## Language changes
|
||||||
|
|
|
||||||
|
|
@ -801,12 +801,14 @@ proc newLit*[T](s: set[T]): NimNode {.compileTime.} =
|
||||||
result = newCall(typ,result)
|
result = newCall(typ,result)
|
||||||
|
|
||||||
proc isNamedTuple(T: typedesc): bool {.magic: "TypeTrait".}
|
proc isNamedTuple(T: typedesc): bool {.magic: "TypeTrait".}
|
||||||
## See typetraits.isNamedTuple
|
## See `typetraits.isNamedTuple`
|
||||||
|
|
||||||
proc newLit*[T: tuple](arg: T): NimNode {.compileTime.} =
|
proc newLit*[T: tuple](arg: T): NimNode {.compileTime.} =
|
||||||
|
## use -d:nimHasWorkaround14720 to restore behavior prior to PR, forcing
|
||||||
|
## a named tuple even when `arg` is unnamed.
|
||||||
result = nnkTupleConstr.newTree
|
result = nnkTupleConstr.newTree
|
||||||
when isNamedTuple(T):
|
when defined(nimHasWorkaround14720) or isNamedTuple(T):
|
||||||
for a,b in arg.fieldPairs:
|
for a, b in arg.fieldPairs:
|
||||||
result.add nnkExprColonExpr.newTree(newIdentNode(a), newLit(b))
|
result.add nnkExprColonExpr.newTree(newIdentNode(a), newLit(b))
|
||||||
else:
|
else:
|
||||||
for b in arg.fields:
|
for b in arg.fields:
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ pkg1 "elvis"
|
||||||
# Error: cannot open 'tests/runNative.nim'
|
# Error: cannot open 'tests/runNative.nim'
|
||||||
pkg1 "fragments", false, "nim c -r fragments/dsl.nim"
|
pkg1 "fragments", false, "nim c -r fragments/dsl.nim"
|
||||||
pkg1 "gara"
|
pkg1 "gara"
|
||||||
pkg1 "ggplotnim", true, "nim c -d:noCairo -r -d:nimWorkaround14447 tests/tests.nim"
|
pkg1 "ggplotnim", true, "nim c -d:noCairo -r -d:nimWorkaround14447 -d:nimHasWorkaround14720 tests/tests.nim"
|
||||||
# pkg1 "gittyup", true, "nimble test", "https://github.com/disruptek/gittyup"
|
# pkg1 "gittyup", true, "nimble test", "https://github.com/disruptek/gittyup"
|
||||||
pkg1 "glob"
|
pkg1 "glob"
|
||||||
pkg1 "gnuplot"
|
pkg1 "gnuplot"
|
||||||
|
|
|
||||||
|
|
@ -194,35 +194,11 @@ static:
|
||||||
doAssert(v == a)
|
doAssert(v == a)
|
||||||
|
|
||||||
echo "macrocache ok"
|
echo "macrocache ok"
|
||||||
|
|
||||||
block tupleNewLitTests:
|
block tupleNewLitTests:
|
||||||
macro t0(): untyped =
|
macro t(): untyped =
|
||||||
result = newLit(())
|
result = newLit (1, "foo", (), (1,), (a1: 'x', a2: @["ba"]))
|
||||||
doAssert t0 == ()
|
doAssert $t() == """(1, "foo", (), (1,), (a1: 'x', a2: @["ba"]))"""
|
||||||
macro t1(): untyped =
|
# this `$` test is needed because tuple equality doesn't distinguish
|
||||||
result = newLit((5,))
|
# between named vs unnamed tuples
|
||||||
doAssert t1 == (5,)
|
doAssert t() == (1, "foo", (), (1, ), (a1: 'x', a2: @["ba"]))
|
||||||
macro t2(): untyped =
|
|
||||||
result = newLit((a: 5))
|
|
||||||
doAssert t2 == (a: 5)
|
|
||||||
macro t3(): untyped =
|
|
||||||
result = newLit((5, "5"))
|
|
||||||
doAssert t3 == (5, "5")
|
|
||||||
macro t4(): untyped =
|
|
||||||
result = newLit((a: 5, b: "5"))
|
|
||||||
doAssert t4 == (a: 5, b: "5")
|
|
||||||
macro t5(): untyped =
|
|
||||||
result = newLit(@[(5,)])
|
|
||||||
doAssert t5 == @[(5,)]
|
|
||||||
macro t6(): untyped =
|
|
||||||
result = newLit(@[(a: 5)])
|
|
||||||
doAssert t6 == @[(a: 5)]
|
|
||||||
macro t7(): untyped =
|
|
||||||
result = newLit(@[(5, "5")])
|
|
||||||
doAssert t7 == @[(5, "5")]
|
|
||||||
macro t8(): untyped =
|
|
||||||
result = newLit(@[(a: 5, b: "5")])
|
|
||||||
doAssert t8 == @[(a: 5, b: "5")]
|
|
||||||
macro t9(): untyped =
|
|
||||||
result = newLit(@[(a: (5, 6), b: ())])
|
|
||||||
doAssert t9 == @[(a: (5, 6), b: ())]
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue