summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--compiler/layouter.nim10
-rw-r--r--nimpretty/tests/expected/wrong_ind.nim24
-rw-r--r--nimpretty/tests/wrong_ind.nim24
3 files changed, 57 insertions, 1 deletions
diff --git a/compiler/layouter.nim b/compiler/layouter.nim
index ddcb5a976..336b09fa7 100644
--- a/compiler/layouter.nim
+++ b/compiler/layouter.nim
@@ -113,6 +113,10 @@ const
   openPars = {tkParLe, tkParDotLe,
               tkBracketLe, tkBracketLeColon, tkCurlyDotLe,
               tkCurlyLe}
+  closedPars = {tkParRi, tkParDotRi,
+              tkBracketRi, tkCurlyDotRi,
+              tkCurlyRi}
+
   splitters = openPars + {tkComma, tkSemicolon}
   oprSet = {tkOpr, tkDiv, tkMod, tkShl, tkShr, tkIn, tkNotin, tkIs,
             tkIsnot, tkNot, tkOf, tkAs, tkDotDot, tkAnd, tkOr, tkXor}
@@ -196,8 +200,12 @@ proc emitTok*(em: var Emitter; L: TLexer; tok: TToken) =
     em.fixedUntil = em.content.high
 
   elif tok.indent >= 0:
-    if em.lastTok in (splitters + oprSet) or em.keepIndents > 0:
+    if em.keepIndents > 0:
       em.indentLevel = tok.indent
+    elif (em.lastTok in (splitters + oprSet) and tok.tokType notin closedPars):
+      # aka: we are in an expression context:
+      let alignment = tok.indent - em.indentStack[^1]
+      em.indentLevel = alignment + em.indentStack.high * em.indWidth
     else:
       if tok.indent > em.indentStack[^1]:
         em.indentStack.add tok.indent
diff --git a/nimpretty/tests/expected/wrong_ind.nim b/nimpretty/tests/expected/wrong_ind.nim
new file mode 100644
index 000000000..a21e94618
--- /dev/null
+++ b/nimpretty/tests/expected/wrong_ind.nim
@@ -0,0 +1,24 @@
+
+# bug #9505
+
+import std/[
+    strutils, ospaths, os
+]
+import pkg/[
+  regex
+]
+
+proc fun() =
+    let a = [
+      1,
+      2,
+    ]
+    discard
+
+proc funB() =
+    let a = [
+      1,
+      2,
+      3
+    ]
+    discard
diff --git a/nimpretty/tests/wrong_ind.nim b/nimpretty/tests/wrong_ind.nim
new file mode 100644
index 000000000..0559673f8
--- /dev/null
+++ b/nimpretty/tests/wrong_ind.nim
@@ -0,0 +1,24 @@
+
+# bug #9505
+
+import std/[
+    strutils, ospaths, os
+]
+import pkg/[
+  regex
+]
+
+proc fun() =
+  let a = [
+    1,
+    2,
+  ]
+  discard
+
+proc funB() =
+  let a = [
+    1,
+    2,
+    3
+  ]
+  discard