Skip to content

Commit 102b71f

Browse files
authored
Merge pull request #11740 from nim-lang/araq-fixes-11723
fixes #11723
2 parents 8550a81 + 76f9ddb commit 102b71f

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

lib/pure/strformat.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ proc parseStandardFormatSpecifier*(s: string; start = 0;
415415
raise newException(ValueError,
416416
"invalid format string, cannot parse: " & s[i..^1])
417417

418-
proc formatValue*(result: var string; value: SomeInteger; specifier: string) =
418+
proc formatValue*[T: SomeInteger](result: var string; value: T; specifier: string) =
419419
## Standard format implementation for ``SomeInteger``. It makes little
420420
## sense to call this directly, but it is required to exist
421421
## by the ``&`` macro.
@@ -509,7 +509,7 @@ proc formatValue*(result: var string; value: string; specifier: string) =
509509
setLen(value, runeOffset(value, spec.precision))
510510
result.add alignString(value, spec.minimumWidth, spec.align, spec.fill)
511511

512-
proc formatValue[T](result: var string; value: T; specifier: string) =
512+
proc formatValue[T: not SomeInteger](result: var string; value: T; specifier: string) =
513513
mixin `$`
514514
formatValue(result, $value, specifier)
515515

tests/stdlib/tstrformat.nim

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,21 @@ proc print_object(animalAddr: AnimalRef) =
115115
echo fmt"Received {animalAddr[]}"
116116

117117
print_object(AnimalRef(name: "Foo", species: "Bar"))
118+
119+
# bug #11723
120+
121+
let pos: Positive = 64
122+
doAssert fmt"{pos:3}" == " 64"
123+
doAssert fmt"{pos:3b}" == "1000000"
124+
doAssert fmt"{pos:3d}" == " 64"
125+
doAssert fmt"{pos:3o}" == "100"
126+
doAssert fmt"{pos:3x}" == " 40"
127+
doAssert fmt"{pos:3X}" == " 40"
128+
129+
let nat: Natural = 64
130+
doAssert fmt"{nat:3}" == " 64"
131+
doAssert fmt"{nat:3b}" == "1000000"
132+
doAssert fmt"{nat:3d}" == " 64"
133+
doAssert fmt"{nat:3o}" == "100"
134+
doAssert fmt"{nat:3x}" == " 40"
135+
doAssert fmt"{nat:3X}" == " 40"

0 commit comments

Comments
 (0)