summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorTimothee Cour <timothee.cour2@gmail.com>2020-06-23 01:06:36 -0700
committerGitHub <noreply@github.com>2020-06-23 10:06:36 +0200
commit511bd947d3a90a5ffedc994a45a36c4eeca63856 (patch)
tree4620ecd835918d1bbbdc4ef41cffd790356dd451
parent235d8ba069b122f34dee3ab12a34d2fba73326ce (diff)
downloadNim-511bd947d3a90a5ffedc994a45a36c4eeca63856.tar.gz
fix bug in semgnrc: runnableExamples should not semcheck, even with > 1 arg (#14768)
-rw-r--r--compiler/semgnrc.nim2
-rw-r--r--tests/nimdoc/trunnableexamples.nim10
2 files changed, 11 insertions, 1 deletions
diff --git a/compiler/semgnrc.nim b/compiler/semgnrc.nim
index 23b6e9b9d..3366732ca 100644
--- a/compiler/semgnrc.nim
+++ b/compiler/semgnrc.nim
@@ -265,7 +265,7 @@ proc semGenericStmt(c: PContext, n: PNode,
         # We're not interested in the example code during this pass so let's
         # skip it
         if s.magic == mRunnableExamples:
-          inc first
+          first = result.safeLen # see trunnableexamples.fun3
       of skGenericParam:
         result[0] = newSymNodeTypeDesc(s, fn.info)
         onUse(fn.info, s)
diff --git a/tests/nimdoc/trunnableexamples.nim b/tests/nimdoc/trunnableexamples.nim
index 73cfacd43..6232011cb 100644
--- a/tests/nimdoc/trunnableexamples.nim
+++ b/tests/nimdoc/trunnableexamples.nim
@@ -91,6 +91,16 @@ when true: # runnableExamples with rdoccmd
   proc fun2*() =
     runnableExamples "-d:foo": discard # checks that it also works inside procs
 
+  template fun3Impl(): untyped =
+    runnableExamples(rdoccmd="-d:foo"):
+      nonexistant
+        # bugfix: this shouldn't be semchecked when `runnableExamples`
+        # has more than 1 argument
+    discard
+
+  proc fun3*[T]() =
+    fun3Impl()
+
   when false: # future work
     # passing non-string-litterals (for reuse)
     const a = "-b:cpp"