mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
fix spurious indent and newlines in rendering of nkRecList (#23121)
Rendering of `nkRecList` produces an indent and adds a new line at the
end. However for things like case object `of`/`else` branches or `when`
branches this is already done, so this produces 2 indents and an extra
new line. Instead, just add an indent in the place where the indent that
`nkRecList` produces is needed, for the rendering of the final node of
`nkObjectTy`. There doesn't seem to be a need to add the newline.
Before:
```nim
case x*: bool
of true:
y*: int
of false:
nil
```
After:
```nim
case x*: bool
of true:
y*: int
of false:
nil
```
(cherry picked from commit fc49c6e3ba)
This commit is contained in:
@@ -1526,17 +1526,16 @@ proc gsub(g: var TSrcGen, n: PNode, c: TContext, fromStmtList = false) =
|
||||
gsub(g, n[0])
|
||||
gsub(g, n[1])
|
||||
gcoms(g)
|
||||
indentNL(g)
|
||||
gsub(g, n[2])
|
||||
dedent(g)
|
||||
else:
|
||||
put(g, tkObject, "object")
|
||||
of nkRecList:
|
||||
indentNL(g)
|
||||
for i in 0..<n.len:
|
||||
optNL(g)
|
||||
gsub(g, n[i], c)
|
||||
gcoms(g)
|
||||
dedent(g)
|
||||
putNL(g)
|
||||
of nkOfInherit:
|
||||
putWithSpace(g, tkOf, "of")
|
||||
gsub(g, n, 0)
|
||||
|
||||
@@ -347,8 +347,7 @@ proc getTypeImpl*(n: NimNode): NimNode {.magic: "NGetType", noSideEffect.} =
|
||||
newLit(x.getTypeImpl.repr)
|
||||
let t = """
|
||||
object
|
||||
arr: array[0 .. 3, float32]
|
||||
"""
|
||||
arr: array[0 .. 3, float32]"""
|
||||
doAssert(dumpTypeImpl(a) == t)
|
||||
doAssert(dumpTypeImpl(b) == t)
|
||||
doAssert(dumpTypeImpl(c) == t)
|
||||
|
||||
@@ -95,8 +95,7 @@
|
||||
<h1><a class="toc-backref" href="#7">Types</a></h1>
|
||||
<dl class="item">
|
||||
<div id="A">
|
||||
<dt><pre><a href="main.html#A"><span class="Identifier">A</span></a> <span class="Other">=</span> <span class="Keyword">object</span>
|
||||
</pre></dt>
|
||||
<dt><pre><a href="main.html#A"><span class="Identifier">A</span></a> <span class="Other">=</span> <span class="Keyword">object</span></pre></dt>
|
||||
<dd>
|
||||
|
||||
|
||||
|
||||
@@ -253,8 +253,7 @@ Ref. <a class="reference internal nimdoc" title="proc `[]`[T](x: G[T]): T" href=
|
||||
<h1><a class="toc-backref" href="#7">Types</a></h1>
|
||||
<dl class="item">
|
||||
<div id="G">
|
||||
<dt><pre><a href="utils.html#G"><span class="Identifier">G</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span> <span class="Other">=</span> <span class="Keyword">object</span>
|
||||
</pre></dt>
|
||||
<dt><pre><a href="utils.html#G"><span class="Identifier">G</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span> <span class="Other">=</span> <span class="Keyword">object</span></pre></dt>
|
||||
<dd>
|
||||
|
||||
|
||||
|
||||
@@ -59,8 +59,7 @@
|
||||
<li><a class="reference" href="#AnotherObject" title="AnotherObject = object
|
||||
case x*: bool
|
||||
of true:
|
||||
y*: proc (x: string)
|
||||
|
||||
y*: proc (x: string)
|
||||
of false:">AnotherObject</a></li>
|
||||
<li><a class="reference" href="#B" title="B {.inject.} = enum
|
||||
bB">B</a></li>
|
||||
@@ -380,11 +379,8 @@
|
||||
<dt><pre><a href="testproject.html#AnotherObject"><span class="Identifier">AnotherObject</span></a> <span class="Other">=</span> <span class="Keyword">object</span>
|
||||
<span class="Keyword">case</span> <span class="Identifier">x</span><span class="Operator">*</span><span class="Other">:</span> <span class="Identifier">bool</span>
|
||||
<span class="Keyword">of</span> <span class="Identifier">true</span><span class="Other">:</span>
|
||||
<span class="Identifier">y</span><span class="Operator">*</span><span class="Other">:</span> <span class="Keyword">proc</span> <span class="Other">(</span><span class="Identifier">x</span><span class="Other">:</span> <span class="Identifier">string</span><span class="Other">)</span>
|
||||
|
||||
<span class="Keyword">of</span> <span class="Identifier">false</span><span class="Other">:</span>
|
||||
|
||||
</pre></dt>
|
||||
<span class="Identifier">y</span><span class="Operator">*</span><span class="Other">:</span> <span class="Keyword">proc</span> <span class="Other">(</span><span class="Identifier">x</span><span class="Other">:</span> <span class="Identifier">string</span><span class="Other">)</span>
|
||||
<span class="Keyword">of</span> <span class="Identifier">false</span><span class="Other">:</span></pre></dt>
|
||||
<dd>
|
||||
|
||||
|
||||
@@ -423,8 +419,7 @@
|
||||
<div id="MyObject">
|
||||
<dt><pre><a href="testproject.html#MyObject"><span class="Identifier">MyObject</span></a> <span class="Other">=</span> <span class="Keyword">object</span>
|
||||
<span class="Identifier">someString</span><span class="Operator">*</span><span class="Other">:</span> <span class="Identifier">string</span> <span class="Comment">## This is a string</span>
|
||||
<span class="Identifier">annotated</span><span class="Operator">*</span> {.<span class="Identifier">somePragma</span>.}<span class="Other">:</span> <span class="Identifier">string</span> <span class="Comment">## This is an annotated string</span>
|
||||
</pre></dt>
|
||||
<span class="Identifier">annotated</span><span class="Operator">*</span> {.<span class="Identifier">somePragma</span>.}<span class="Other">:</span> <span class="Identifier">string</span> <span class="Comment">## This is an annotated string</span></pre></dt>
|
||||
<dd>
|
||||
|
||||
|
||||
@@ -444,8 +439,7 @@
|
||||
</div>
|
||||
<div id="T19396">
|
||||
<dt><pre><a href="testproject.html#T19396"><span class="Identifier">T19396</span></a> <span class="Other">=</span> <span class="Keyword">object</span>
|
||||
<span class="Identifier">a</span><span class="Operator">*</span><span class="Other">:</span> <span class="Identifier">int</span>
|
||||
</pre></dt>
|
||||
<span class="Identifier">a</span><span class="Operator">*</span><span class="Other">:</span> <span class="Identifier">int</span></pre></dt>
|
||||
<dd>
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user