Fixes #11662: render ops priority (#11664)

(cherry picked from commit d1f6c820dd)
This commit is contained in:
cooldome
2019-07-05 20:25:36 +01:00
committed by narimiran
parent 88896194bd
commit cb3a920097
2 changed files with 12 additions and 4 deletions

View File

@@ -898,16 +898,19 @@ proc accentedName(g: var TSrcGen, n: PNode) =
gsub(g, n)
proc infixArgument(g: var TSrcGen, n: PNode, i: int) =
if i >= n.len: return
if i < 1 and i > 2: return
var needsParenthesis = false
let n_next = n[i].skipHiddenNodes
if n_next.kind == nkInfix:
if n_next[0].kind in {nkSym, nkIdent} and n[0].kind in {nkSym, nkIdent}:
let nextId = if n_next[0].kind == nkSym: n_next[0].sym.name else: n_next[0].ident
let nnId = if n[0].kind == nkSym: n[0].sym.name else: n[0].ident
if getPrecedence(nextId) < getPrecedence(nnId):
needsParenthesis = true
if i == 1:
if getPrecedence(nextId) < getPrecedence(nnId):
needsParenthesis = true
elif i == 2:
if getPrecedence(nextId) <= getPrecedence(nnId):
needsParenthesis = true
if needsParenthesis:
put(g, tkParLe, "(")
gsub(g, n, i)