parser: fix panic, discovered by fuzzing examples/2048/2048.v with zzuf on the CI

This commit is contained in:
Delyan Angelov 2025-03-09 12:16:32 +02:00
parent 309aebfaf1
commit aebe9bc1c8
No known key found for this signature in database
GPG key ID: 66886C0F12D595ED

View file

@ -75,8 +75,11 @@ fn (mut p Parser) array_init(is_option bool, alias_array_type ast.Type) ast.Arra
|| (p.tok.kind == .lsbr && p.is_array_type())) { || (p.tok.kind == .lsbr && p.is_array_type())) {
// [100]u8 // [100]u8
elem_type = p.parse_type() elem_type = p.parse_type()
if p.table.sym(elem_type).name == 'byte' { if elem_type != 0 {
p.error('`byte` has been deprecated in favor of `u8`: use `[10]u8{}` instead of `[10]byte{}`') s := p.table.sym(elem_type)
if s.name == 'byte' {
p.error('`byte` has been deprecated in favor of `u8`: use `[10]u8{}` instead of `[10]byte{}`')
}
} }
last_pos = p.tok.pos() last_pos = p.tok.pos()
is_fixed = true is_fixed = true