Render bug: if expression with statement list expression as condition (#8375)
* Fixes #8348
This commit is contained in:
parent
5ea3b4d581
commit
ec02940185
3 changed files with 29 additions and 5 deletions
|
|
@ -568,6 +568,7 @@ proc parsePar(p: var TParser): PNode =
|
||||||
result = newNodeP(nkPar, p)
|
result = newNodeP(nkPar, p)
|
||||||
getTok(p)
|
getTok(p)
|
||||||
optInd(p, result)
|
optInd(p, result)
|
||||||
|
flexComment(p, result)
|
||||||
if p.tok.tokType in {tkDiscard, tkInclude, tkIf, tkWhile, tkCase,
|
if p.tok.tokType in {tkDiscard, tkInclude, tkIf, tkWhile, tkCase,
|
||||||
tkTry, tkDefer, tkFinally, tkExcept, tkFor, tkBlock,
|
tkTry, tkDefer, tkFinally, tkExcept, tkFor, tkBlock,
|
||||||
tkConst, tkLet, tkWhen, tkVar,
|
tkConst, tkLet, tkWhen, tkVar,
|
||||||
|
|
|
||||||
|
|
@ -634,9 +634,16 @@ proc gstmts(g: var TSrcGen, n: PNode, c: TContext, doIndent=true) =
|
||||||
optNL(g)
|
optNL(g)
|
||||||
|
|
||||||
|
|
||||||
|
proc gcond(g: var TSrcGen, n: PNode) =
|
||||||
|
if n.kind == nkStmtListExpr:
|
||||||
|
put(g, tkParLe, "(")
|
||||||
|
gsub(g, n)
|
||||||
|
if n.kind == nkStmtListExpr:
|
||||||
|
put(g, tkParRi, ")")
|
||||||
|
|
||||||
proc gif(g: var TSrcGen, n: PNode) =
|
proc gif(g: var TSrcGen, n: PNode) =
|
||||||
var c: TContext
|
var c: TContext
|
||||||
gsub(g, n.sons[0].sons[0])
|
gcond(g, n.sons[0].sons[0])
|
||||||
initContext(c)
|
initContext(c)
|
||||||
putWithSpace(g, tkColon, ":")
|
putWithSpace(g, tkColon, ":")
|
||||||
if longMode(g, n) or (lsub(g, n.sons[0].sons[1]) + g.lineLen > MaxLineLen):
|
if longMode(g, n) or (lsub(g, n.sons[0].sons[1]) + g.lineLen > MaxLineLen):
|
||||||
|
|
@ -651,7 +658,7 @@ proc gif(g: var TSrcGen, n: PNode) =
|
||||||
proc gwhile(g: var TSrcGen, n: PNode) =
|
proc gwhile(g: var TSrcGen, n: PNode) =
|
||||||
var c: TContext
|
var c: TContext
|
||||||
putWithSpace(g, tkWhile, "while")
|
putWithSpace(g, tkWhile, "while")
|
||||||
gsub(g, n.sons[0])
|
gcond(g, n.sons[0])
|
||||||
putWithSpace(g, tkColon, ":")
|
putWithSpace(g, tkColon, ":")
|
||||||
initContext(c)
|
initContext(c)
|
||||||
if longMode(g, n) or (lsub(g, n.sons[1]) + g.lineLen > MaxLineLen):
|
if longMode(g, n) or (lsub(g, n.sons[1]) + g.lineLen > MaxLineLen):
|
||||||
|
|
@ -715,7 +722,7 @@ proc gcase(g: var TSrcGen, n: PNode) =
|
||||||
var last = if n.sons[length-1].kind == nkElse: -2 else: -1
|
var last = if n.sons[length-1].kind == nkElse: -2 else: -1
|
||||||
if longMode(g, n, 0, last): incl(c.flags, rfLongMode)
|
if longMode(g, n, 0, last): incl(c.flags, rfLongMode)
|
||||||
putWithSpace(g, tkCase, "case")
|
putWithSpace(g, tkCase, "case")
|
||||||
gsub(g, n.sons[0])
|
gcond(g, n.sons[0])
|
||||||
gcoms(g)
|
gcoms(g)
|
||||||
optNL(g)
|
optNL(g)
|
||||||
gsons(g, n, c, 1, last)
|
gsons(g, n, c, 1, last)
|
||||||
|
|
@ -1102,13 +1109,13 @@ proc gsub(g: var TSrcGen, n: PNode, c: TContext) =
|
||||||
put(g, tkAccent, "`")
|
put(g, tkAccent, "`")
|
||||||
of nkIfExpr:
|
of nkIfExpr:
|
||||||
putWithSpace(g, tkIf, "if")
|
putWithSpace(g, tkIf, "if")
|
||||||
if n.len > 0: gsub(g, n.sons[0], 0)
|
if n.len > 0: gcond(g, n.sons[0].sons[0])
|
||||||
putWithSpace(g, tkColon, ":")
|
putWithSpace(g, tkColon, ":")
|
||||||
if n.len > 0: gsub(g, n.sons[0], 1)
|
if n.len > 0: gsub(g, n.sons[0], 1)
|
||||||
gsons(g, n, emptyContext, 1)
|
gsons(g, n, emptyContext, 1)
|
||||||
of nkElifExpr:
|
of nkElifExpr:
|
||||||
putWithSpace(g, tkElif, " elif")
|
putWithSpace(g, tkElif, " elif")
|
||||||
gsub(g, n, 0)
|
gcond(g, n[0])
|
||||||
putWithSpace(g, tkColon, ":")
|
putWithSpace(g, tkColon, ":")
|
||||||
gsub(g, n, 1)
|
gsub(g, n, 1)
|
||||||
of nkElseExpr:
|
of nkElseExpr:
|
||||||
|
|
|
||||||
|
|
@ -57,5 +57,21 @@ proc test_block(x, y : int): int =
|
||||||
result = x
|
result = x
|
||||||
result = y
|
result = y
|
||||||
|
|
||||||
|
#------------------------------------
|
||||||
|
# bugs #8348
|
||||||
|
|
||||||
|
template `>`(x, y: untyped): untyped =
|
||||||
|
## "is greater" operator. This is the same as ``y < x``.
|
||||||
|
y < x
|
||||||
|
|
||||||
|
proc test_cond_stmtlist(x, y: int): int =
|
||||||
|
result = x
|
||||||
|
if x > y:
|
||||||
|
result = x
|
||||||
|
|
||||||
|
|
||||||
repr_and_parse(one_if_proc)
|
repr_and_parse(one_if_proc)
|
||||||
repr_and_parse(test_block)
|
repr_and_parse(test_block)
|
||||||
|
repr_and_parse(test_cond_stmtlist)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue