Skip to content

Commit b4626a2

Browse files
committed
Added $ for openarrays. Fixes #7940.
1 parent cb87bba commit b4626a2

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

lib/system.nim

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3443,6 +3443,14 @@ when not defined(nimNoArrayToString):
34433443
## generic ``$`` operator for arrays that is lifted from the components
34443444
collectionToString(x, "[", ", ", "]")
34453445
3446+
proc `$`*[T](x: openarray[T]): string =
3447+
## generic ``$`` operator for openarrays that is lifted from the components
3448+
## of `x`. Example:
3449+
##
3450+
## .. code-block:: nim
3451+
## $(@[23, 45].toOpenArray(0, 1)) == "[23, 45]"
3452+
collectionToString(x, "[", ", ", "]")
3453+
34463454
proc quit*(errormsg: string, errorcode = QuitFailure) {.noReturn.} =
34473455
## a shorthand for ``echo(errormsg); quit(errorcode)``.
34483456
echo(errormsg)

tests/system/toString.nim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ doAssert "@[23, 45]" == $(@[23, 45])
66
doAssert "[32, 45]" == $([32, 45])
77
doAssert """@["", "foo", "bar"]""" == $(@["", "foo", "bar"])
88
doAssert """["", "foo", "bar"]""" == $(["", "foo", "bar"])
9+
doAssert """["", "foo", "bar"]""" == $(@["", "foo", "bar"].toOpenArray(0, 2))
910

1011
# bug #2395
1112
let alphaSet: set[char] = {'a'..'c'}

0 commit comments

Comments
 (0)