mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parser: fix enum attr with default value (#18248)
This commit is contained in:
parent
099d4fc06f
commit
e8dbd2c0c7
@ -481,8 +481,8 @@ pub fn (mut p Parser) expr_with_left(left ast.Expr, precedence int, is_stmt_iden
|
||||
return node
|
||||
}
|
||||
p.is_stmt_ident = is_stmt_ident
|
||||
} else if p.tok.kind in [.lsbr, .nilsbr] && (p.tok.line_nr == p.prev_tok.line_nr
|
||||
|| (p.prev_tok.kind == .string
|
||||
} else if left !is ast.IntegerLiteral && p.tok.kind in [.lsbr, .nilsbr]
|
||||
&& (p.tok.line_nr == p.prev_tok.line_nr || (p.prev_tok.kind == .string
|
||||
&& p.tok.line_nr == p.prev_tok.line_nr + p.prev_tok.lit.count('\n'))) {
|
||||
if p.tok.kind == .nilsbr {
|
||||
node = p.index_expr(node, true)
|
||||
|
14
vlib/v/tests/enum_attr_2_test.v
Normal file
14
vlib/v/tests/enum_attr_2_test.v
Normal file
@ -0,0 +1,14 @@
|
||||
enum Color {
|
||||
red = 1 + 1 [json: 'Red']
|
||||
blue = 10 / 2 [json: 'Blue']
|
||||
}
|
||||
|
||||
fn test_main() {
|
||||
$for e in Color.values {
|
||||
if e.name == 'red' {
|
||||
assert e.value == Color.red
|
||||
} else if e.name == 'blue' {
|
||||
assert e.value == Color.blue
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user