mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-12 22:33:49 +00:00
add legacy workaround; improve test so that it actually tests for the bugfix
This commit is contained in:
committed by
Andreas Rumpf
parent
408518c9fe
commit
9c42ae91b7
@@ -112,6 +112,7 @@
|
||||
- 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 `os.normalizeExe`, eg: `koch` => `./koch`.
|
||||
- `macros.newLit` now preserves named vs unnamed tuples; use `-d:nimHasWorkaround14720` to keep old behavior
|
||||
|
||||
|
||||
## Language changes
|
||||
|
||||
@@ -801,12 +801,14 @@ proc newLit*[T](s: set[T]): NimNode {.compileTime.} =
|
||||
result = newCall(typ,result)
|
||||
|
||||
proc isNamedTuple(T: typedesc): bool {.magic: "TypeTrait".}
|
||||
## See typetraits.isNamedTuple
|
||||
## See `typetraits.isNamedTuple`
|
||||
|
||||
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
|
||||
when isNamedTuple(T):
|
||||
for a,b in arg.fieldPairs:
|
||||
when defined(nimHasWorkaround14720) or isNamedTuple(T):
|
||||
for a, b in arg.fieldPairs:
|
||||
result.add nnkExprColonExpr.newTree(newIdentNode(a), newLit(b))
|
||||
else:
|
||||
for b in arg.fields:
|
||||
|
||||
@@ -43,7 +43,7 @@ pkg1 "elvis"
|
||||
# Error: cannot open 'tests/runNative.nim'
|
||||
pkg1 "fragments", false, "nim c -r fragments/dsl.nim"
|
||||
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 "glob"
|
||||
pkg1 "gnuplot"
|
||||
|
||||
@@ -194,35 +194,11 @@ static:
|
||||
doAssert(v == a)
|
||||
|
||||
echo "macrocache ok"
|
||||
|
||||
|
||||
block tupleNewLitTests:
|
||||
macro t0(): untyped =
|
||||
result = newLit(())
|
||||
doAssert t0 == ()
|
||||
macro t1(): untyped =
|
||||
result = newLit((5,))
|
||||
doAssert t1 == (5,)
|
||||
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: ())]
|
||||
macro t(): untyped =
|
||||
result = newLit (1, "foo", (), (1,), (a1: 'x', a2: @["ba"]))
|
||||
doAssert $t() == """(1, "foo", (), (1,), (a1: 'x', a2: @["ba"]))"""
|
||||
# this `$` test is needed because tuple equality doesn't distinguish
|
||||
# between named vs unnamed tuples
|
||||
doAssert t() == (1, "foo", (), (1, ), (a1: 'x', a2: @["ba"]))
|
||||
|
||||
Reference in New Issue
Block a user