1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

parser: force {} blocks on new lines

This commit is contained in:
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

@ -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')