refs #17292 fix repr: (discard) now does't render as discard which gave illegal code (#17455)

* refs #17292 fix `repr` with (discard)
* add tests
* add more tests
This commit is contained in:
Timothee Cour
2021-04-16 05:55:51 -07:00
committed by GitHub
parent fdd4391534
commit 1b65b9cc19
2 changed files with 45 additions and 13 deletions

View File

@@ -1461,7 +1461,13 @@ proc gsub(g: var TSrcGen, n: PNode, c: TContext, fromStmtList = false) =
put(g, tkSpaces, Space)
putWithSpace(g, tkEquals, "=")
gsub(g, n, 1)
of nkStmtList, nkStmtListExpr, nkStmtListType: gstmts(g, n, emptyContext)
of nkStmtList, nkStmtListExpr, nkStmtListType:
if n.len == 1 and n[0].kind == nkDiscardStmt:
put(g, tkParLe, "(")
gsub(g, n[0])
put(g, tkParRi, ")")
else:
gstmts(g, n, emptyContext)
of nkIfStmt:
putWithSpace(g, tkIf, "if")
gif(g, n)