From 754e11de3e6916e3768c9f4c8ca12c10fcd6389a Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Tue, 16 Oct 2018 15:33:21 +0200 Subject: [PATCH] nimpretty: fixes #8626 (cherry picked from commit ed38079b9ba56ae494995e0eb594b824b45d5ad9) --- compiler/layouter.nim | 4 ++-- compiler/parser.nim | 2 ++ nimpretty/tester.nim | 9 ++++++++- nimpretty/tests/exhaustive.nim | 5 +++++ nimpretty/tests/expected/exhaustive.nim | 5 +++++ 5 files changed, 22 insertions(+), 3 deletions(-) diff --git a/compiler/layouter.nim b/compiler/layouter.nim index cc6ec48b77..d03105eb29 100644 --- a/compiler/layouter.nim +++ b/compiler/layouter.nim @@ -31,7 +31,7 @@ type inquote: bool semicolons: SemicolonKind col, lastLineNumber, lineSpan, indentLevel, indWidth: int - nested: int + inParamList*: int doIndentMore*: int content: string indentStack: seq[int] @@ -142,7 +142,7 @@ proc emitTok*(em: var Emitter; L: TLexer; tok: TToken) = em.fixedUntil = em.content.high elif tok.indent >= 0: - if em.lastTok in (splitters + oprSet): + if em.lastTok in (splitters + oprSet) or em.inParamList > 0: em.indentLevel = tok.indent else: if tok.indent > em.indentStack[^1]: diff --git a/compiler/parser.nim b/compiler/parser.nim index 54aaf81941..cf64ad5556 100644 --- a/compiler/parser.nim +++ b/compiler/parser.nim @@ -1037,6 +1037,7 @@ proc parseParamList(p: var TParser, retColon = true): PNode = addSon(result, p.emptyNode) # return type when defined(nimpretty2): inc p.em.doIndentMore + inc p.em.inParamList let hasParLe = p.tok.tokType == tkParLe and p.tok.indent < 0 if hasParLe: getTok(p) @@ -1073,6 +1074,7 @@ proc parseParamList(p: var TParser, retColon = true): PNode = result = p.emptyNode when defined(nimpretty2): dec p.em.doIndentMore + dec p.em.inParamList proc optPragmas(p: var TParser): PNode = if p.tok.tokType == tkCurlyDotLe and (p.tok.indent < 0 or realInd(p)): diff --git a/nimpretty/tester.nim b/nimpretty/tester.nim index 8798ce06ae..2f184b7fc6 100644 --- a/nimpretty/tester.nim +++ b/nimpretty/tester.nim @@ -8,8 +8,15 @@ const var failures = 0 +when defined(develop): + const nimp = "bin/nimpretty".addFileExt(ExeExt) + if execShellCmd("nim c -o:$# nimpretty/nimpretty.nim" % [nimp]) != 0: + quit("FAILURE: compilation of nimpretty failed") +else: + const nimp = "nimpretty" + proc test(infile, outfile: string) = - if execShellCmd("nimpretty -o:$2 --backup:off $1" % [infile, outfile]) != 0: + if execShellCmd("$# -o:$# --backup:off $#" % [nimp, outfile, infile]) != 0: quit("FAILURE") let nimFile = splitFile(infile).name let expected = dir / "expected" / nimFile & ".nim" diff --git a/nimpretty/tests/exhaustive.nim b/nimpretty/tests/exhaustive.nim index 1b80078449..cfb42e7a9f 100644 --- a/nimpretty/tests/exhaustive.nim +++ b/nimpretty/tests/exhaustive.nim @@ -316,3 +316,8 @@ proc f() = str &= c const test = r"C:\Users\-\Desktop\test.txt" + +proc getKeyAndData(cursor: int, op: int): + tuple[key, data: string, success: bool] {.noInit.} = + var keyVal: string + var dataVal: string diff --git a/nimpretty/tests/expected/exhaustive.nim b/nimpretty/tests/expected/exhaustive.nim index bace619457..b9cb2e053d 100644 --- a/nimpretty/tests/expected/exhaustive.nim +++ b/nimpretty/tests/expected/exhaustive.nim @@ -325,3 +325,8 @@ proc f() = str &= c const test = r"C:\Users\-\Desktop\test.txt" + +proc getKeyAndData(cursor: int; op: int): + tuple[key, data: string; success: bool] {.noInit.} = + var keyVal: string + var dataVal: string