summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--compiler/semcall.nim9
-rw-r--r--lib/pure/strutils.nim12
-rw-r--r--tests/reject/tinvalidborrow.nim17
3 files changed, 29 insertions, 9 deletions
diff --git a/compiler/semcall.nim b/compiler/semcall.nim
index 735e6fac8..a29efcd8a 100644
--- a/compiler/semcall.nim
+++ b/compiler/semcall.nim
@@ -207,11 +207,14 @@ proc SearchForBorrowProc(c: PContext, startScope: PScope, fn: PSym): PSym =
   # New approach: generate fn(x, y, z) where x, y, z have the proper types
   # and use the overloading resolution mechanism:
   var call = newNode(nkCall)
+  var hasDistinct = false
   call.add(newIdentNode(fn.name, fn.info))
   for i in 1.. <fn.typ.n.len:
     let param = fn.typ.n.sons[i]
     let t = skipTypes(param.typ, abstractVar-{tyTypeDesc})
+    if t.kind == tyDistinct or param.typ.kind == tyDistinct: hasDistinct = true
     call.add(newNodeIT(nkEmpty, fn.info, t.baseOfDistinct))
-  var resolved = semOverloadedCall(c, call, call, {fn.kind})
-  if resolved != nil:
-    result = resolved.sons[0].sym
+  if hasDistinct:
+    var resolved = semOverloadedCall(c, call, call, {fn.kind})
+    if resolved != nil:
+      result = resolved.sons[0].sym
diff --git a/lib/pure/strutils.nim b/lib/pure/strutils.nim
index 73dd9132c..a4aa81578 100644
--- a/lib/pure/strutils.nim
+++ b/lib/pure/strutils.nim
@@ -1030,8 +1030,8 @@ type
     ffScientific       ## use scientific notation (using ``e`` character)

 

 proc formatBiggestFloat*(f: BiggestFloat, format: TFloatFormat = ffDefault,

-                         precision = 16): string {.noSideEffect, operator: 2,

-                                                  rtl, extern: "nsu$1".} =

+                         precision: range[0..32] = 16): string {.
+                         noSideEffect, operator: 2, rtl, extern: "nsu$1".} =

   ## converts a floating point value `f` to a string.

   ##

   ## If ``format == ffDecimal`` then precision is the number of digits to

@@ -1041,11 +1041,11 @@ proc formatBiggestFloat*(f: BiggestFloat, format: TFloatFormat = ffDefault,
   ## `precision`'s default value is the maximum number of meaningful digits

   ## after the decimal point for Nimrod's ``biggestFloat`` type.
   ## 
-  ## If ``precision == 0``, it uses the 

+  ## If ``precision == 0``, it tries to format it nicely.

   const floatFormatToChar: array[TFloatFormat, char] = ['g', 'f', 'e']

   var

     frmtstr {.noinit.}: array[0..5, char]

-    buf: array[0..80, char]

+    buf {.noinit.}: array[0..2500, char]

   frmtstr[0] = '%'

   if precision > 0:

     frmtstr[1] = '#'

@@ -1061,8 +1061,8 @@ proc formatBiggestFloat*(f: BiggestFloat, format: TFloatFormat = ffDefault,
   result = $buf

 

 proc formatFloat*(f: float, format: TFloatFormat = ffDefault,

-                  precision = 16): string {.noSideEffect, operator: 2,

-                                           rtl, extern: "nsu$1".} =

+                  precision: range[0..32] = 16): string {.
+                  noSideEffect, operator: 2, rtl, extern: "nsu$1".} =

   ## converts a floating point value `f` to a string.

   ##

   ## If ``format == ffDecimal`` then precision is the number of digits to

diff --git a/tests/reject/tinvalidborrow.nim b/tests/reject/tinvalidborrow.nim
new file mode 100644
index 000000000..9ab9e8d64
--- /dev/null
+++ b/tests/reject/tinvalidborrow.nim
@@ -0,0 +1,17 @@
+discard """
+  line: 11
+  errormsg: "no symbol to borrow from found"
+"""
+
+# bug #516
+
+type
+  TAtom = culong
+
+proc `==`*(a, b: TAtom): bool {.borrow.}
+
+var
+  d, e: TAtom
+
+echo( $(d == e) )
+