diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim
index 97cf7c5ece..21667895a2 100644
--- a/compiler/semtypes.nim
+++ b/compiler/semtypes.nim
@@ -133,7 +133,8 @@ proc semEnum(c: PContext, n: PNode, prev: PType): PType =
e.typ = result
e.position = int(counter)
let symNode = newSymNode(e)
- if optNimV1Emulation notin c.config.globalOptions and identToReplace != nil:
+ if optNimV1Emulation notin c.config.globalOptions and identToReplace != nil and
+ c.config.cmd != cmdDoc: # A hack to produce documentation for enum fields.
identToReplace[] = symNode
if e.position == 0: hasNull = true
if result.sym != nil and sfExported in result.sym.flags:
diff --git a/nimdoc/testproject/expected/testproject.html b/nimdoc/testproject/expected/testproject.html
index 103dea25fd..d9132d087b 100644
--- a/nimdoc/testproject/expected/testproject.html
+++ b/nimdoc/testproject/expected/testproject.html
@@ -109,6 +109,11 @@ function main() {
Foo
+ Shapes
@@ -406,6 +411,16 @@ The enum B.
+
+
+Shapes = enum
+ Circle,
+ Triangle,
+ Rectangle
+
+
+Some shapes.
+
diff --git a/nimdoc/testproject/expected/testproject.idx b/nimdoc/testproject/expected/testproject.idx
index 0b75b29d2e..8d132acc4f 100644
--- a/nimdoc/testproject/expected/testproject.idx
+++ b/nimdoc/testproject/expected/testproject.idx
@@ -54,3 +54,7 @@ asyncFun1 testproject.html#asyncFun1 testproject: asyncFun1(): Future[int]
asyncFun2 testproject.html#asyncFun2 testproject: asyncFun2(): owned(Future[void])
asyncFun3 testproject.html#asyncFun3 testproject: asyncFun3(): owned(Future[void])
testNimDocTrailingExample testproject.html#testNimDocTrailingExample.t testproject: testNimDocTrailingExample()
+Circle testproject.html#Circle Shapes.Circle
+Triangle testproject.html#Triangle Shapes.Triangle
+Rectangle testproject.html#Rectangle Shapes.Rectangle
+Shapes testproject.html#Shapes testproject: Shapes
diff --git a/nimdoc/testproject/expected/theindex.html b/nimdoc/testproject/expected/theindex.html
index 66dea92fcc..34d24e9005 100644
--- a/nimdoc/testproject/expected/theindex.html
+++ b/nimdoc/testproject/expected/theindex.html
@@ -132,6 +132,10 @@ function main() {
testproject: C_D
+Circle:
c_nonexistant:
+Rectangle:
+Shapes:
someFunc:
+Triangle:
tripleStrLitTest:
- testproject: tripleStrLitTest()
diff --git a/nimdoc/testproject/testproject.nim b/nimdoc/testproject/testproject.nim
index 25cdf39a49..ffddc356f6 100644
--- a/nimdoc/testproject/testproject.nim
+++ b/nimdoc/testproject/testproject.nim
@@ -363,4 +363,12 @@ when true:
# where runnableExamples would not show if there was not at least 2 "\n" after
# the last character of runnableExamples
runnableExamples:
- discard 2
\ No newline at end of file
+ discard 2
+
+when true: # issue #15702
+ type
+ Shapes* = enum
+ ## Some shapes.
+ Circle, ## A circle
+ Triangle, ## A three-sided shape
+ Rectangle ## A four-sided shape