diff options
-rw-r--r-- | compiler/ast.nim | 5 | ||||
-rw-r--r-- | compiler/docgen.nim | 7 | ||||
-rw-r--r-- | compiler/semtempl.nim | 4 |
3 files changed, 9 insertions, 7 deletions
diff --git a/compiler/ast.nim b/compiler/ast.nim index 55970596b..e158ab913 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -1660,6 +1660,11 @@ proc isCompileTimeProc*(s: PSym): bool {.inline.} = result = s.kind == skMacro or s.kind == skProc and sfCompileTime in s.flags +proc isRunnableExamples*(n: PNode): bool = + # Templates and generics don't perform symbol lookups. + result = n.kind == nkSym and n.sym.magic == mRunnableExamples or + n.kind == nkIdent and n.ident.s == "runnableExamples" + proc requiredParams*(s: PSym): int = # Returns the number of required params (without default values) # XXX: Perhaps we can store this in the `offset` field of the diff --git a/compiler/docgen.nim b/compiler/docgen.nim index 226dffa90..07f0e0378 100644 --- a/compiler/docgen.nim +++ b/compiler/docgen.nim @@ -398,16 +398,11 @@ proc prepareExamples(d: PDoc; n: PNode) = runnableExamples.add newTree(nkBlockStmt, newNode(nkEmpty), copyTree savedLastSon) testExample(d, runnableExamples) -proc isRunnableExample(n: PNode): bool = - # Templates and generics don't perform symbol lookups. - result = n.kind == nkSym and n.sym.magic == mRunnableExamples or - n.kind == nkIdent and n.ident.s == "runnableExamples" - proc getAllRunnableExamplesRec(d: PDoc; n, orig: PNode; dest: var Rope) = if n.info.fileIndex != orig.info.fileIndex: return case n.kind of nkCallKinds: - if isRunnableExample(n[0]) and + if isRunnableExamples(n[0]) and n.len >= 2 and n.lastSon.kind == nkStmtList: prepareExamples(d, n) dispA(d.conf, dest, "\n<p><strong class=\"examples_text\">$1</strong></p>\n", diff --git a/compiler/semtempl.nim b/compiler/semtempl.nim index 396696422..484a7ddd6 100644 --- a/compiler/semtempl.nim +++ b/compiler/semtempl.nim @@ -493,7 +493,9 @@ proc semTemplBody(c: var TemplCtx, n: PNode): PNode = else: result = semTemplBodySons(c, n) of nkCallKinds-{nkPostfix}: - result = semTemplBodySons(c, n) + # do not transform runnableExamples (bug #9143) + if not isRunnableExamples(n[0]): + result = semTemplBodySons(c, n) of nkDotExpr, nkAccQuoted: # dotExpr is ambiguous: note that we explicitly allow 'x.TemplateParam', # so we use the generic code for nkDotExpr too |