diff --git a/compiler/evaltempl.nim b/compiler/evaltempl.nim
index d6c630e79b..43d5a8698c 100644
--- a/compiler/evaltempl.nim
+++ b/compiler/evaltempl.nim
@@ -17,6 +17,7 @@ type
TemplCtx = object
owner, genSymOwner: PSym
instLines: bool # use the instantiation lines numbers
+ isDeclarative: bool
mapping: TIdTable # every gensym'ed symbol needs to be mapped to some
# new symbol
config: ConfigRef
@@ -54,11 +55,30 @@ proc evalTemplateAux(templ, actual: PNode, c: var TemplCtx, result: PNode) =
result.add copyNode(c, templ, actual)
of nkNone..nkIdent, nkType..nkNilLit: # atom
result.add copyNode(c, templ, actual)
+ of nkCommentStmt:
+ # for the documentation generator we don't keep documentation comments
+ # in the AST that would confuse it (bug #9432), but only if we are not in a
+ # "declarative" context (bug #9235).
+ if c.isDeclarative:
+ var res = copyNode(c, templ, actual)
+ for i in countup(0, sonsLen(templ) - 1):
+ evalTemplateAux(templ.sons[i], actual, c, res)
+ result.add res
+ else:
+ result.add newNodeI(nkEmpty, templ.info)
else:
+ var isDeclarative = false
+ if templ.kind in {nkProcDef, nkFuncDef, nkMethodDef, nkIteratorDef,
+ nkMacroDef, nkTemplateDef, nkConverterDef, nkTypeSection,
+ nkVarSection, nkLetSection, nkConstSection} and
+ not c.isDeclarative:
+ c.isDeclarative = true
+ isDeclarative = true
var res = copyNode(c, templ, actual)
for i in countup(0, sonsLen(templ) - 1):
evalTemplateAux(templ.sons[i], actual, c, res)
result.add res
+ if isDeclarative: c.isDeclarative = false
const
errWrongNumberOfArguments = "wrong number of arguments"
diff --git a/nimdoc/testproject/expected/subdir/subdir_b/utils.html b/nimdoc/testproject/expected/subdir/subdir_b/utils.html
index 5ccb6c8320..2c89acce45 100644
--- a/nimdoc/testproject/expected/subdir/subdir_b/utils.html
+++ b/nimdoc/testproject/expected/subdir/subdir_b/utils.html
@@ -1255,6 +1255,16 @@ function main() {
+
+ Templates
+
+
@@ -1282,6 +1292,23 @@ function main() {
constructor.
+
+
+
+
+
+
+
+template aEnum(): untyped
+-
+
+
+
+
+template bEnum(): untyped
+-
+
+
diff --git a/nimdoc/testproject/expected/testproject.html b/nimdoc/testproject/expected/testproject.html
index 96fba4a0ff..2e23a64d50 100644
--- a/nimdoc/testproject/expected/testproject.html
+++ b/nimdoc/testproject/expected/testproject.html
@@ -1244,6 +1244,18 @@ function main() {
+
+ Types
+
+
Vars
@@ -1257,6 +1269,16 @@ function main() {
+
+
+ Funcs
+
@@ -1293,6 +1315,25 @@ function main() {
subdir/subdir_b/utils
+
+
+
+
+
+A {...}{.inject.} = enum
+ aA
+-
+The enum A.
+
+
+
+B {...}{.inject.} = enum
+ bB
+-
+The enum B.
+
+
+
@@ -1313,6 +1354,23 @@ function main() {
+
+
+
proc isValid[T](x: T): bool
+
+
+
+
+
+
+
+
+
+
+func someFunc() {...}{.raises: [], tags: [].}
+-
+My someFunc.
+
diff --git a/nimdoc/testproject/expected/theindex.html b/nimdoc/testproject/expected/theindex.html
index 865e5a28ee..652077be87 100644
--- a/nimdoc/testproject/expected/theindex.html
+++ b/nimdoc/testproject/expected/theindex.html
@@ -1221,16 +1221,32 @@ function main() {
Index
Modules:
subdir/subdir_b/utils,
testproject.
API symbols
-
- aVariable:
+- A:
+- aEnum:
+- aVariable:
+- B:
- bar:
+- bEnum:
- enumValueA:
+- isValid:
+- someFunc:
- SomeType:
- utils: SomeType
diff --git a/nimdoc/testproject/subdir/subdir_b/utils.nim b/nimdoc/testproject/subdir/subdir_b/utils.nim
index d7d82b3cd5..e2ec80dc25 100644
--- a/nimdoc/testproject/subdir/subdir_b/utils.nim
+++ b/nimdoc/testproject/subdir/subdir_b/utils.nim
@@ -8,3 +8,19 @@ type
proc someType*(): SomeType =
## constructor.
SomeType(2)
+
+# bug #9235
+
+template aEnum*(): untyped =
+ type
+ A* {.inject.} = enum ## The enum A.
+ aA
+
+template bEnum*(): untyped =
+ type
+ B* {.inject.} = enum ## The enum B.
+ bB
+
+ func someFunc*() =
+ ## My someFunc.
+ discard
diff --git a/nimdoc/testproject/testproject.nim b/nimdoc/testproject/testproject.nim
index 3274660143..d6fac47512 100644
--- a/nimdoc/testproject/testproject.nim
+++ b/nimdoc/testproject/testproject.nim
@@ -22,3 +22,9 @@ macro bar*(): untyped =
result = newStmtList()
var aVariable*: array[1,int]
+
+aEnum()
+bEnum()
+
+# bug #9432
+proc isValid*[T](x: T): bool = x.len > 0