fixes #25027; nim doc uses doc comment from private field for public field (#25239)

fixes #25027

(cherry picked from commit b8ce11dd9d)
This commit is contained in:
ringabout
2025-10-24 01:19:27 +08:00
committed by narimiran
parent f1373637e7
commit 4eaecfe59e
5 changed files with 33 additions and 0 deletions

View File

@@ -327,6 +327,10 @@ proc pushCom(g: var TSrcGen, n: PNode) =
setLen(g.comStack, g.comStack.len + 1)
g.comStack[^1] = n
proc popCom(g: var TSrcGen): PNode =
result = g.comStack[^1]
setLen(g.comStack, g.comStack.len - 1)
proc popAllComs(g: var TSrcGen) =
setLen(g.comStack, 0)
@@ -1353,6 +1357,10 @@ proc gsub(g: var TSrcGen, n: PNode, c: TContext, fromStmtList = false) =
if not n[0].isExported() and renderNonExportedFields notin g.flags:
# Skip if this is a property in a type and its not exported
# (While also not allowing rendering of non exported fields)
if shouldRenderComment(g, n):
# `shouldRenderComment` indicts that we have comments to render
# but it's a non-exported field, so we just pop without rendering any comment
discard popCom(g)
return
# render postfix for object fields:
exclFlags = g.flags * {renderNoPostfix}

View File

@@ -82,6 +82,9 @@
Rectangle ## A four-sided shape">Shapes</a></li>
<li><a class="reference" href="#T19396" title="T19396 = object
a*: int">T19396</a></li>
<li><a class="reference" href="#Xxx" title="Xxx = object
field*: int
field3*: int ## Doc comment2">Xxx</a></li>
</ul>
</details>
@@ -455,6 +458,16 @@
</dd>
</div>
<div id="Xxx">
<dt><pre><a href="testproject.html#Xxx"><span class="Identifier">Xxx</span></a> <span class="Other">=</span> <span class="Keyword">object</span>
<span class="Identifier">field</span><span class="Operator">*</span><span class="Other">:</span> <span class="Identifier">int</span>
<span class="Identifier">field3</span><span class="Operator">*</span><span class="Other">:</span> <span class="Identifier">int</span> <span class="Comment">## Doc comment2</span></pre></dt>
<dd>
</dd>
</div>

View File

@@ -67,6 +67,7 @@ nim T19396 testproject.html#T19396 object T19396 404
nim somePragma testproject.html#somePragma.t template somePragma() 408
nim MyObject testproject.html#MyObject object MyObject 412
nim AnotherObject testproject.html#AnotherObject object AnotherObject 417
nim Xxx testproject.html#Xxx object Xxx 424
nimgrp bar testproject.html#bar-procs-all proc 43
nimgrp baz testproject.html#baz-procs-all proc 46
heading Basic usage testproject.html#basic-usage Basic usage 0

View File

@@ -342,6 +342,10 @@
<li><a class="reference external"
data-doc-search-tag="testproject: proc tripleStrLitTest()" href="testproject.html#tripleStrLitTest">testproject: proc tripleStrLitTest()</a></li>
</ul></dd>
<dt><a name="Xxx" href="#Xxx"><span>Xxx:</span></a></dt><dd><ul class="simple">
<li><a class="reference external"
data-doc-search-tag="testproject: object Xxx" href="testproject.html#Xxx">testproject: object Xxx</a></li>
</ul></dd>
<dt><a name="z1" href="#z1"><span>z1:</span></a></dt><dd><ul class="simple">
<li><a class="reference external"
data-doc-search-tag="testproject: proc z1(): Foo" href="testproject.html#z1">testproject: proc z1(): Foo</a></li>

View File

@@ -420,3 +420,10 @@ type
y*: proc (x: string)
of false:
hidden: string
type Xxx* = object
field*: int
field2: int
## Doc comment
field3*: int
## Doc comment2