1
0
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:
Felipe Pena 2023-05-24 11:25:27 -03:00 committed by GitHub
parent 099d4fc06f
commit e8dbd2c0c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 2 deletions

View File

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

View 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
}
}
}