mirror of
https://github.com/vlang/v.git
synced 2025-09-19 12:27:02 -04:00
comptime: fix missing bool AttributeKind.kind (#23159)
This commit is contained in:
parent
78389c8a45
commit
b39cad2f24
@ -153,6 +153,7 @@ pub enum AttributeKind {
|
|||||||
plain // [name]
|
plain // [name]
|
||||||
string // ['name']
|
string // ['name']
|
||||||
number // [123]
|
number // [123]
|
||||||
|
bool // [true] || [false]
|
||||||
comptime_define // [if name]
|
comptime_define // [if name]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2045,7 +2045,7 @@ fn (mut p Parser) parse_attr(is_at bool) ast.Attr {
|
|||||||
if p.tok.kind == .colon {
|
if p.tok.kind == .colon {
|
||||||
has_arg = true
|
has_arg = true
|
||||||
p.next()
|
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
|
kind = .plain
|
||||||
arg = p.check_name()
|
arg = p.check_name()
|
||||||
} else if p.tok.kind == .number { // `name: 123`
|
} 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
|
kind = .bool
|
||||||
arg = p.tok.kind.str()
|
arg = p.tok.kind.str()
|
||||||
p.next()
|
p.next()
|
||||||
|
} else if token.is_key(p.tok.lit) { // // `name: keyword`
|
||||||
|
kind = .plain
|
||||||
|
arg = p.check_name()
|
||||||
} else {
|
} else {
|
||||||
p.unexpected(additional_msg: 'an argument is expected after `:`')
|
p.unexpected(additional_msg: 'an argument is expected after `:`')
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
@[foo: true]
|
||||||
@[name: 'abc']
|
@[name: 'abc']
|
||||||
@[amount: 2]
|
@[amount: 2]
|
||||||
@[abc]
|
@[abc]
|
||||||
@ -26,8 +27,19 @@ fn test_attributes() {
|
|||||||
} else if attr.has_arg && attr.kind == .number {
|
} else if attr.has_arg && attr.kind == .number {
|
||||||
assert attr.name == 'amount'
|
assert attr.name == 'amount'
|
||||||
assert attr.arg == '2'
|
assert attr.arg == '2'
|
||||||
} else {
|
} else if attr.kind != .bool {
|
||||||
assert attr.name == 'abc'
|
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