1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

v.parser: allow for if x { $if y {} } else {}, fix #10243 (#10294)

This commit is contained in:
Wertzui123 2021-06-01 11:19:39 +02:00 committed by GitHub
parent 98505207c4
commit 148bb31f6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 55 additions and 11 deletions

View File

@ -134,7 +134,7 @@ fn (mut p Parser) if_expr(is_comptime bool) ast.IfExpr {
p.error('use `\$else` instead of `else` in compile-time `if` branches')
return ast.IfExpr{}
}
if p.peek_tok.kind == .key_else {
if p.tok.kind != .rcbr && p.peek_tok.kind == .key_else {
p.check(.dollar)
}
}

View File

@ -0,0 +1,54 @@
fn test_comptime_if_test() {
mut i := 0
$if test {
i++
}
$if !test {
i--
}
assert i == 1
}
fn test_comptime_if_parsing_in_combination_with_ordinary_if_1() {
if true {
$if debug {
println('debug')
}
} else {
assert false
}
assert true
}
fn test_comptime_if_parsing_in_combination_with_ordinary_if_2() {
if true {
if true {
$if debug {
println('debug')
}
} else {
assert false
}
} else {
assert false
}
assert true
}
fn test_comptime_if_parsing_in_combination_with_ordinary_if_3() {
println(@LINE)
$if true {
println(@LINE)
$if true {
println(@LINE)
$if debug {
println('debug')
}
} $else {
assert false
}
} $else {
assert false
}
assert true
}

View File

@ -1,10 +0,0 @@
fn test_comptime_if_test() {
mut i := 0
$if test {
i++
}
$if !test {
i--
}
assert i == 1
}