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

parser: allow enums to be used as bitfield flags

This commit is contained in:
joe-conigliaro
2019-12-10 14:16:47 +11:00
committed by Alexander Medvednikov
parent 0650d58818
commit 6d5e9f88f8
7 changed files with 89 additions and 4 deletions

View File

@ -285,6 +285,10 @@ fn (p mut Parser) struct_init(typ string) string {
p.error('no such field: "$field" in type $typ')
break
}
tt := p.table.find_type(f.typ)
if tt.is_flag {
p.error(err_modify_bitfield)
}
inited_fields << field
p.gen_struct_field_init(field)
p.check(.colon)
@ -361,6 +365,10 @@ fn (p mut Parser) struct_init(typ string) string {
if !p.check_types_no_throw(expr_typ, ffield.typ) {
p.error('field value #${i+1} `$ffield.name` has type `$ffield.typ`, got `$expr_typ` ')
}
tt := p.table.find_type(ffield.typ)
if tt.is_flag {
p.error(err_modify_bitfield)
}
if i < T.fields.len - 1 {
if p.tok != .comma {
p.error('too few values in `$typ` literal (${i+1} instead of $T.fields.len)')