From 6982f4a5a2e43f60eeee6d4f1b38b843990d1c43 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Thu, 12 Dec 2019 20:22:11 +0300 Subject: [PATCH] parser: force {} blocks on new lines --- README.md | 2 ++ vlib/compiler/parser.v | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/README.md b/README.md index 7f126bccec..e57c215fad 100644 --- a/README.md +++ b/README.md @@ -148,6 +148,7 @@ git clone --depth=1 https://github.com/ubawurinna/freetype-windows-binaries [pat glfw dependency will be removed soon. + ## Troubleshooting: diff --git a/vlib/compiler/parser.v b/vlib/compiler/parser.v index 8b51196c83..4c299e635d 100644 --- a/vlib/compiler/parser.v +++ b/vlib/compiler/parser.v @@ -1307,6 +1307,12 @@ fn (p mut Parser) statement(add_semi bool) string { p.return_st() } .lcbr {// {} block + // Do not allow {} block to start on the same line + // to avoid e.g. `foo() {` instead of `if foo() {` + if p.prev_token().line_nr == p.scanner.line_nr { + p.genln('') + p.error('{} block has to start on a new line') + } p.check(.lcbr) if p.tok == .rcbr { p.error('empty statements block')