compiler/parser: fix single element in array error

pull/2148/head
luoheng 2019-09-28 18:50:30 +08:00 committed by Alexander Medvednikov
parent a4d2633a33
commit 5348c667cc
1 changed files with 9 additions and 6 deletions

View File

@ -2893,11 +2893,10 @@ fn (p mut Parser) array_init() string {
if i == 0 { if i == 0 {
typ = val_typ typ = val_typ
// fixed width array initialization? (`arr := [20]byte`) // fixed width array initialization? (`arr := [20]byte`)
if is_integer && p.tok == .rsbr && p.peek() == .name { if is_integer && p.tok == .rsbr && p.peek() == .name &&
//nextc := p.scanner.text[p.scanner.pos + 1] p.cur_tok().line_nr == p.peek_token().line_nr {
// TODO whitespace hack // there is no space between `[10]` and `byte`
// Make sure there's no space in `[10]byte` if p.cur_tok().col + p.peek_token().lit.len == p.peek_token().col {
//if !nextc.is_space() {
p.check(.rsbr) p.check(.rsbr)
array_elem_typ := p.get_type() array_elem_typ := p.get_type()
if !p.table.known_type(array_elem_typ) { if !p.table.known_type(array_elem_typ) {
@ -2910,7 +2909,11 @@ fn (p mut Parser) array_init() string {
return '[${p.mod}__$lit]$array_elem_typ' return '[${p.mod}__$lit]$array_elem_typ'
} }
return '[$lit]$array_elem_typ' return '[$lit]$array_elem_typ'
//} } else {
p.check(.rsbr)
typ = p.get_type()
p.error('no space allowed between [$lit] and $typ')
}
} }
} }
if val_typ != typ { if val_typ != typ {