summary refs log tree commit diff stats
path: root/lib/system
diff options
context:
space:
mode:
authorMiran <narimiran@disroot.org>2019-05-21 21:32:37 +0200
committerAndreas Rumpf <rumpf_a@web.de>2019-05-21 21:32:37 +0200
commitbab5e30972743d9dc343c9c4d3ad06f3645e5741 (patch)
treeff12fa2cf76541227d47a1d4f6123f7ca20ef253 /lib/system
parentf94ec363abf5b1393014a0bca7202c405512cddd (diff)
downloadNim-bab5e30972743d9dc343c9c4d3ad06f3645e5741.tar.gz
fixes #10963, disallow implicit mixing of strings and ints/floats (#11292)
Diffstat (limited to 'lib/system')
-rw-r--r--lib/system/strmantle.nim22
1 files changed, 15 insertions, 7 deletions
diff --git a/lib/system/strmantle.nim b/lib/system/strmantle.nim
index 4aa1b705f..8ff2e0ee0 100644
--- a/lib/system/strmantle.nim
+++ b/lib/system/strmantle.nim
@@ -40,14 +40,14 @@ proc hashString(s: string): int {.compilerproc.} =
   h = h +% h shl 15
   result = h
 
-proc add*(result: var string; x: int64) =
+proc addInt*(result: var string; x: int64) =
   ## Converts integer to its string representation and appends it to `result`.
   ##
   ## .. code-block:: Nim
   ##   var
   ##     a = "123"
   ##     b = 45
-  ##   a.add(b) # a <- "12345"
+  ##   a.addInt(b) # a <- "12345"
   let base = result.len
   setLen(result, base + sizeof(x)*4)
   var i = 0
@@ -66,18 +66,22 @@ proc add*(result: var string; x: int64) =
   for j in 0..i div 2 - 1:
     swap(result[base+j], result[base+i-j-1])
 
+proc add*(result: var string; x: int64) {.deprecated:
+  "Deprecated since v0.20, use 'addInt'".} =
+  addInt(result, x)
+
 proc nimIntToStr(x: int): string {.compilerRtl.} =
   result = newStringOfCap(sizeof(x)*4)
-  result.add x
+  result.addInt x
 
-proc add*(result: var string; x: float) =
+proc addFloat*(result: var string; x: float) =
   ## Converts float to its string representation and appends it to `result`.
   ##
   ## .. code-block:: Nim
   ##   var
   ##     a = "123"
   ##     b = 45.67
-  ##   a.add(b) # a <- "12345.67"
+  ##   a.addFloat(b) # a <- "12345.67"
   when nimvm:
     result.add $x
   else:
@@ -113,9 +117,13 @@ proc add*(result: var string; x: float) =
         result.add buf[i]
         inc i
 
+proc add*(result: var string; x: float) {.deprecated:
+  "Deprecated since v0.20, use 'addFloat'".} =
+  addFloat(result, x)
+
 proc nimFloatToStr(f: float): string {.compilerproc.} =
   result = newStringOfCap(8)
-  result.add f
+  result.addFloat f
 
 proc c_strtod(buf: cstring, endptr: ptr cstring): float64 {.
   importc: "strtod", header: "<stdlib.h>", noSideEffect.}
@@ -284,7 +292,7 @@ proc nimParseBiggestFloat(s: string, number: var BiggestFloat,
 
 proc nimInt64ToStr(x: int64): string {.compilerRtl.} =
   result = newStringOfCap(sizeof(x)*4)
-  result.add x
+  result.addInt x
 
 proc nimBoolToStr(x: bool): string {.compilerRtl.} =
   return if x: "true" else: "false"