summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorflywind <43030857+xflywind@users.noreply.github.com>2021-01-29 07:31:41 -0600
committerGitHub <noreply@github.com>2021-01-29 14:31:41 +0100
commitf09d97d6d37520e41aa295e43b6901ce49132aac (patch)
treeaf135856c250586c7154fa2076b79121e670e537 /compiler
parent6e267d28b3459aa447cae07ba61209438977cd5c (diff)
downloadNim-f09d97d6d37520e41aa295e43b6901ce49132aac.tar.gz
close #16844 (#16852)
* close #16844
* better
* comment
* Update compiler/renderer.nim
Diffstat (limited to 'compiler')
-rw-r--r--compiler/renderer.nim14
1 files changed, 14 insertions, 0 deletions
diff --git a/compiler/renderer.nim b/compiler/renderer.nim
index 765bcded5..93ccde02a 100644
--- a/compiler/renderer.nim
+++ b/compiler/renderer.nim
@@ -820,14 +820,28 @@ proc gTypeClassTy(g: var TSrcGen, n: PNode) =
   dedent(g)
 
 proc gblock(g: var TSrcGen, n: PNode) =
+  # you shouldn't simplify it to `n.len < 2`
+  # because the following codes should be executed
+  # even when block stmt has only one child for getting
+  # better error messages.
+  if n.len == 0:
+    return
+
   var c: TContext
   initContext(c)
+
   if n[0].kind != nkEmpty:
     putWithSpace(g, tkBlock, "block")
     gsub(g, n[0])
   else:
     put(g, tkBlock, "block")
+
+  # block stmt should have two children
+  if n.len == 1:
+    return
+
   putWithSpace(g, tkColon, ":")
+
   if longMode(g, n) or (lsub(g, n[1]) + g.lineLen > MaxLineLen):
     incl(c.flags, rfLongMode)
   gcoms(g)