[bugfix] fix wrong nimpretty unidents, refs #11616 (#11645)

This commit is contained in:
Miran 2019-07-03 18:55:15 +02:00 • committed by GitHub
commit 0718d6c2cd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 1 deletions

View file

@ -364,7 +364,7 @@ proc emitTok*(em: var Emitter; L: TLexer; tok: TToken) =
em.indentLevel = tok.indent em.indentLevel = tok.indent
elif (em.lastTok in (splitters + oprSet) and tok.tokType notin closedPars): elif (em.lastTok in (splitters + oprSet) and tok.tokType notin closedPars):
# aka: we are in an expression context: # aka: we are in an expression context:
let alignment = tok.indent - em.indentStack[^1] let alignment = max(tok.indent - em.indentStack[^1], 0)
em.indentLevel = alignment + em.indentStack.high * em.indWidth em.indentLevel = alignment + em.indentStack.high * em.indWidth
else: else:
if tok.indent > em.indentStack[^1]: if tok.indent > em.indentStack[^1]:

View file

@ -676,3 +676,15 @@ block:
## single line comment would be ok. ## single line comment would be ok.
block: block:
var x = 7 var x = 7
proc newRecordGen(ctx: Context; typ: TypRef): PNode =
result = nkTypeDef.t(
newId(typ.optSym.name, true, pragmas = [id(if typ.isUnion: "cUnion" else: "cStruct")]),
empty(),
nkObjectTy.t(
empty(),
empty(),
nkRecList.t(
typ.recFields.map(newRecFieldGen))))

View file

@ -682,3 +682,16 @@ block:
## single line comment would be ok. ## single line comment would be ok.
block: block:
var x = 7 var x = 7
proc newRecordGen(ctx: Context; typ: TypRef): PNode =
result = nkTypeDef.t(
newId(typ.optSym.name, true, pragmas = [id(
if typ.isUnion: "cUnion" else: "cStruct")]),
empty(),
nkObjectTy.t(
empty(),
empty(),
nkRecList.t(
typ.recFields.map(newRecFieldGen))))