diff options
author | Araq <rumpf_a@web.de> | 2020-04-20 10:33:07 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2020-04-20 14:44:54 +0200 |
commit | 17f222613a90b0113277baaaa87b856bea74f209 (patch) | |
tree | 5be34f8110b2306c7779b2cf332325c3da33fdbc | |
parent | b2720317fa3b31aed298398696124b439fcfa907 (diff) | |
download | Nim-17f222613a90b0113277baaaa87b856bea74f209.tar.gz |
refactor system.$ for objects a little; refs #13398
-rw-r--r-- | lib/system/dollars.nim | 12 |
1 files changed, 3 insertions, 9 deletions
diff --git a/lib/system/dollars.nim b/lib/system/dollars.nim index 3414c6db1..8e10dae4b 100644 --- a/lib/system/dollars.nim +++ b/lib/system/dollars.nim @@ -75,28 +75,22 @@ proc `$`*[T: tuple|object](x: T): string = ## $(a: 23, b: 45) == "(a: 23, b: 45)" ## $() == "()" result = "(" - # when x is empty, this gives an unused warning - var firstElement {.used.} = true const isNamed = T is object or isNamedTuple(T) - when not isNamed: - var count = 0 + var count = 0 for name, value in fieldPairs(x): - if not firstElement: result.add(", ") + if count > 0: result.add(", ") when isNamed: result.add(name) result.add(": ") - else: - count.inc + count.inc when compiles($value): when value isnot string and value isnot seq and compiles(value.isNil): if value.isNil: result.add "nil" else: result.addQuoted(value) else: result.addQuoted(value) - firstElement = false else: result.add("...") - firstElement = false when not isNamed: if count == 1: result.add(",") # $(1,) should print as the semantically legal (1,) |