parser: force {} blocks on new lines

pull/3067/head
Alexander Medvednikov 2019-12-12 20:22:11 +03:00
parent 02c29624d8
commit 6982f4a5a2
2 changed files with 8 additions and 0 deletions

View File

@ -148,6 +148,7 @@ git clone --depth=1 https://github.com/ubawurinna/freetype-windows-binaries [pat
glfw dependency will be removed soon. glfw dependency will be removed soon.
<!---
## JavaScript backend ## JavaScript backend
[examples/hello_v_js.v](examples/hello_v_js.v): [examples/hello_v_js.v](examples/hello_v_js.v):
@ -166,6 +167,7 @@ Hello from V.js
Hello from V.js Hello from V.js
Hello from V.js Hello from V.js
``` ```
-->
## Troubleshooting: ## Troubleshooting:

View File

@ -1307,6 +1307,12 @@ fn (p mut Parser) statement(add_semi bool) string {
p.return_st() p.return_st()
} }
.lcbr {// {} block .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) p.check(.lcbr)
if p.tok == .rcbr { if p.tok == .rcbr {
p.error('empty statements block') p.error('empty statements block')