summary refs log tree commit diff stats
path: root/compiler/renderer.nim
diff options
context:
space:
mode:
authorTimothee Cour <timothee.cour2@gmail.com>2021-04-16 05:55:51 -0700
committerGitHub <noreply@github.com>2021-04-16 14:55:51 +0200
commit1b65b9cc193791285f63fcf9d52f19da72fffd4f (patch)
treedad554d58b7022c20c8f1d6cc50a3e9b6a54232b /compiler/renderer.nim
parentfdd4391534578d6a5a655eef99ef96e53ff2b4f1 (diff)
downloadNim-1b65b9cc193791285f63fcf9d52f19da72fffd4f.tar.gz
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
Diffstat (limited to 'compiler/renderer.nim')
-rw-r--r--compiler/renderer.nim8
1 files changed, 7 insertions, 1 deletions
diff --git a/compiler/renderer.nim b/compiler/renderer.nim
index b3b0adc01..4c0de9ed5 100644
--- a/compiler/renderer.nim
+++ b/compiler/renderer.nim
@@ -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)