summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--compiler/semstmts.nim5
-rw-r--r--tests/borrow/typeclassborrow.nim18
2 files changed, 20 insertions, 3 deletions
diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim
index 26356a33c..596995adb 100644
--- a/compiler/semstmts.nim
+++ b/compiler/semstmts.nim
@@ -2130,10 +2130,11 @@ proc semProcAux(c: PContext, n: PNode, kind: TSymKind,
         localError(c.config, n.info, "the overloaded " & s.name.s &
           " operator has to be enabled with {.experimental: \"callOperator\".}")
 
+  if sfBorrow in s.flags and c.config.cmd notin cmdDocLike:
+    result[bodyPos] = c.graph.emptyNode
+
   if n[bodyPos].kind != nkEmpty and sfError notin s.flags:
     # for DLL generation we allow sfImportc to have a body, for use in VM
-    if sfBorrow in s.flags:
-      localError(c.config, n[bodyPos].info, errImplOfXNotAllowed % s.name.s)
     if c.config.ideCmd in {ideSug, ideCon} and s.kind notin {skMacro, skTemplate} and not
         cursorInProc(c.config, n[bodyPos]):
       # speed up nimsuggest
diff --git a/tests/borrow/typeclassborrow.nim b/tests/borrow/typeclassborrow.nim
index 62cb77d67..ee0b07829 100644
--- a/tests/borrow/typeclassborrow.nim
+++ b/tests/borrow/typeclassborrow.nim
@@ -29,4 +29,20 @@ baz.doThing()
 
 assert $seq[int](foo) == $foo
 assert $seq[int](bar) == $bar
-assert $seq[int](baz) == $baz
\ No newline at end of file
+assert $seq[int](baz) == $baz
+
+type
+  Fine* = distinct string
+
+proc `==`*(x, y: Fine): bool {.borrow.} =
+  ## Here is the documentation
+  runnableExamples:
+    var x = Fine("1234")
+    var y = Fine("1234")
+    doAssert x == y
+  doAssert false
+
+
+var x = Fine("1234")
+var y = Fine("1234")
+doAssert x == y