diff options
-rw-r--r-- | compiler/docgen.nim | 6 | ||||
-rw-r--r-- | tests/nimdoc/t15916.nim | 16 |
2 files changed, 20 insertions, 2 deletions
diff --git a/compiler/docgen.nim b/compiler/docgen.nim index 8f6b7a560..57fdad12a 100644 --- a/compiler/docgen.nim +++ b/compiler/docgen.nim @@ -592,8 +592,10 @@ proc getRoutineBody(n: PNode): PNode = (0 or more) doc comments and runnableExamples. ]## result = n[bodyPos] - if result.kind == nkAsgn and n.len > bodyPos+1 and n[bodyPos+1].kind == nkSym: - doAssert result[0].kind == nkSym + + # This won't be transformed: result.id = 10. Namely result[0].kind != nkSym. + if result.kind == nkAsgn and result[0].kind == nkSym and + n.len > bodyPos+1 and n[bodyPos+1].kind == nkSym: doAssert result.len == 2 result = result[1] diff --git a/tests/nimdoc/t15916.nim b/tests/nimdoc/t15916.nim new file mode 100644 index 000000000..c6c09d94b --- /dev/null +++ b/tests/nimdoc/t15916.nim @@ -0,0 +1,16 @@ +discard """ +cmd: "nim doc --hints:off $file" +action: "compile" +joinable: false +""" + +type + Test* = object + id: int + +proc initTest*(id: int): Test = + result.id = id + +proc hello*() = + runnableExamples: + discard |