mirror of
https://github.com/vlang/v.git
synced 2025-09-17 03:17:25 -04:00
comptime: fix missing bool AttributeKind.kind (#23159)
This commit is contained in:
parent
78389c8a45
commit
b39cad2f24
@ -153,7 +153,8 @@ pub enum AttributeKind {
|
||||
plain // [name]
|
||||
string // ['name']
|
||||
number // [123]
|
||||
comptime_define // [if name]
|
||||
bool // [true] || [false]
|
||||
comptime_define // [if name]
|
||||
}
|
||||
|
||||
pub struct VAttribute {
|
||||
|
@ -2045,7 +2045,7 @@ fn (mut p Parser) parse_attr(is_at bool) ast.Attr {
|
||||
if p.tok.kind == .colon {
|
||||
has_arg = true
|
||||
p.next()
|
||||
if p.tok.kind == .name || (p.tok.kind != .string && token.is_key(p.tok.lit)) { // `name: arg`
|
||||
if p.tok.kind == .name { // `name: arg`
|
||||
kind = .plain
|
||||
arg = p.check_name()
|
||||
} else if p.tok.kind == .number { // `name: 123`
|
||||
@ -2060,6 +2060,9 @@ fn (mut p Parser) parse_attr(is_at bool) ast.Attr {
|
||||
kind = .bool
|
||||
arg = p.tok.kind.str()
|
||||
p.next()
|
||||
} else if token.is_key(p.tok.lit) { // // `name: keyword`
|
||||
kind = .plain
|
||||
arg = p.check_name()
|
||||
} else {
|
||||
p.unexpected(additional_msg: 'an argument is expected after `:`')
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
@[foo: true]
|
||||
@[name: 'abc']
|
||||
@[amount: 2]
|
||||
@[abc]
|
||||
@ -26,8 +27,19 @@ fn test_attributes() {
|
||||
} else if attr.has_arg && attr.kind == .number {
|
||||
assert attr.name == 'amount'
|
||||
assert attr.arg == '2'
|
||||
} else {
|
||||
} else if attr.kind != .bool {
|
||||
assert attr.name == 'abc'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn test_attr_boolean() {
|
||||
mut bool_fields := []string{}
|
||||
$for attr in Abc.attributes {
|
||||
if attr.kind == .bool {
|
||||
bool_fields << attr.name
|
||||
}
|
||||
}
|
||||
assert bool_fields.len == 1
|
||||
assert bool_fields[0] == 'foo'
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user