diff options
-rw-r--r-- | lib/pure/strformat.nim | 4 | ||||
-rw-r--r-- | tests/stdlib/tstrformat.nim | 13 |
2 files changed, 16 insertions, 1 deletions
diff --git a/lib/pure/strformat.nim b/lib/pure/strformat.nim index e04c80794..d1dedb625 100644 --- a/lib/pure/strformat.nim +++ b/lib/pure/strformat.nim @@ -221,8 +221,10 @@ template callFormat(res, arg) {.dirty.} = template callFormatOption(res, arg, option) {.dirty.} = when compiles(format(arg, option, res)): format(arg, option, res) - else: + elif compiles(format(arg, option)): res.add format(arg, option) + else: + format($arg, option, res) macro fmt*(pattern: string{lit}): untyped = ## For a specification of the ``fmt`` macro, see the module level documentation. diff --git a/tests/stdlib/tstrformat.nim b/tests/stdlib/tstrformat.nim new file mode 100644 index 000000000..4e5c614a7 --- /dev/null +++ b/tests/stdlib/tstrformat.nim @@ -0,0 +1,13 @@ +discard """ + action: "run" +""" + +import strformat + +type Obj = object + +proc `$`(o: Obj): string = "foobar" + +var o: Obj +doAssert fmt"{o}" == "foobar" +doAssert fmt"{o:10}" == "foobar " \ No newline at end of file |