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

@ -0,0 +1,34 @@
[flag]
enum BfPermission {
read
write
execute
other
}
struct BfFile {
mut:
perm BfPermission
}
fn test_enum_bitfield() {
mut a := BfFile{}
a.perm.set(.read)
a.perm.set(.write)
a.perm.toggle(.execute)
a.perm.clear(.write)
//a.perm.set(.other)
assert a.perm.has(.read)
assert a.perm.has(.execute)
assert !a.perm.has(.write)
assert !a.perm.has(.other)
mut b := BfPermission.read // TODO: this does nothing currenty just sets the type
b.set(.write)
b.set(.other)
assert b.has(.write)
assert b.has(.other)
assert !b.has(.read)
assert !b.has(.execute)
}