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:

committed by
Alexander Medvednikov

parent
0650d58818
commit
6d5e9f88f8
@ -1449,6 +1449,10 @@ fn ($v.name mut $v.typ) $p.cur_fn.name (...) {
|
||||
}
|
||||
}
|
||||
else if !p.builtin_mod && !p.check_types_no_throw(expr_type, p.assigned_type) {
|
||||
t := p.table.find_type( p.assigned_type)
|
||||
if t.cat == .enum_ && t.is_flag {
|
||||
p.error_with_token_index(err_modify_bitfield, errtok)
|
||||
}
|
||||
p.error_with_token_index( 'cannot use type `$expr_type` as type `$p.assigned_type` in assignment', errtok)
|
||||
}
|
||||
if (is_str || is_ustr) && tok == .plus_assign && !p.is_js {
|
||||
@ -2792,6 +2796,11 @@ fn (p mut Parser) attribute() {
|
||||
p.attr = ''
|
||||
return
|
||||
}
|
||||
else if p.tok == .key_enum {
|
||||
p.enum_decl(false)
|
||||
p.attr = ''
|
||||
return
|
||||
}
|
||||
p.error_with_token_index('bad attribute usage', attr_token_idx)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user