diff --git a/compiler/docgen.nim b/compiler/docgen.nim
index 0af830a42d..a973bdfc19 100644
--- a/compiler/docgen.nim
+++ b/compiler/docgen.nim
@@ -609,21 +609,12 @@ proc getRoutineBody(n: PNode): PNode =
so we normalize the results to get to the statement list containing the
(0 or more) doc comments and runnableExamples.
- (even if using `result = n[bodyPos]`, you'd still to apply similar logic).
]##
- result = n[^1]
- case result.kind
- of nkSym:
- result = n[^2]
- case result.kind
- of nkAsgn:
- doAssert result[0].kind == nkSym
- doAssert result.len == 2
- result = result[1]
- else: # eg: nkStmtList
- discard
- else:
- discard
+ result = n[bodyPos]
+ if result.kind == nkAsgn and n.len > bodyPos+1 and n[bodyPos+1].kind == nkSym:
+ doAssert result[0].kind == nkSym
+ doAssert result.len == 2
+ result = result[1]
proc getAllRunnableExamples(d: PDoc, n: PNode, dest: var Rope) =
var n = n
diff --git a/nimdoc/testproject/expected/testproject.html b/nimdoc/testproject/expected/testproject.html
index 7bd2e64a33..a4f8876fd8 100644
--- a/nimdoc/testproject/expected/testproject.html
+++ b/nimdoc/testproject/expected/testproject.html
@@ -211,11 +211,27 @@ function main() {
+
+ Methods
+
+
Iterators
@@ -653,6 +669,32 @@ My someFunc. Stuff in quotes
+
+
+
+
+
+method method1(self: Moo) {...}{.raises: [], tags: [].}
+-
+
+foo1
+
+
+
+method method2(self: Moo): int {...}{.raises: [], tags: [].}
+-
+
+foo2
+
+
+
+method method3(self: Moo): int {...}{.raises: [], tags: [].}
+-
+
+foo3
+
+
+
@@ -667,6 +709,22 @@ My someFunc. Stuff in
quotesassert 1 == 1
+
+
+iterator iter1(n: int): int {...}{.raises: [], tags: [].}
+
+
+foo1
+
+
+
+iterator iter2(n: int): int {...}{.raises: [], tags: [].}
+
+
+foo2
+Example:
+discard
+
diff --git a/nimdoc/testproject/expected/testproject.idx b/nimdoc/testproject/expected/testproject.idx
index 46798f3140..6d0bc6c5e7 100644
--- a/nimdoc/testproject/expected/testproject.idx
+++ b/nimdoc/testproject/expected/testproject.idx
@@ -38,6 +38,11 @@ c_nonexistant testproject.html#c_nonexistant,cstring testproject: c_nonexistant(
low testproject.html#low,T testproject: low[T: Ordinal | enum | range](x: T): T
low2 testproject.html#low2,T testproject: low2[T: Ordinal | enum | range](x: T): T
tripleStrLitTest testproject.html#tripleStrLitTest testproject: tripleStrLitTest()
+method1 testproject.html#method1.e,Moo testproject: method1(self: Moo)
+method2 testproject.html#method2.e,Moo testproject: method2(self: Moo): int
+method3 testproject.html#method3.e,Moo testproject: method3(self: Moo): int
+iter1 testproject.html#iter1.i,int testproject: iter1(n: int): int
+iter2 testproject.html#iter2.i,int testproject: iter2(n: int): int
bar testproject.html#bar.m testproject: bar(): untyped
z16 testproject.html#z16.m testproject: z16()
z18 testproject.html#z18.m testproject: z18(): int
diff --git a/nimdoc/testproject/expected/theindex.html b/nimdoc/testproject/expected/theindex.html
index 14d07bfd99..8d34506a61 100644
--- a/nimdoc/testproject/expected/theindex.html
+++ b/nimdoc/testproject/expected/theindex.html
@@ -181,6 +181,14 @@ function main() {
testproject: isValid[T](x: T): bool
+iter1:
+iter2:
low:
+method1:
+method2:
+method3:
myfn:
- testproject: myfn()
diff --git a/nimdoc/testproject/testproject.nim b/nimdoc/testproject/testproject.nim
index b05754d51d..5282c6f778 100644
--- a/nimdoc/testproject/testproject.nim
+++ b/nimdoc/testproject/testproject.nim
@@ -247,6 +247,28 @@ at indent 0
# should be in
# should be out
+when true: # methods; issue #14691
+ type Moo = object
+ method method1*(self: Moo) =
+ ## foo1
+ method method2*(self: Moo): int =
+ ## foo2
+ result = 1
+ method method3*(self: Moo): int =
+ ## foo3
+ 1
+
+when true: # iterators
+ iterator iter1*(n: int): int =
+ ## foo1
+ for i in 0..