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

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