mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parent
98505207c4
commit
148bb31f6e
@ -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)
|
||||
}
|
||||
}
|
||||
|
54
vlib/v/tests/comptime_if_test.v
Normal file
54
vlib/v/tests/comptime_if_test.v
Normal 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
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
fn test_comptime_if_test() {
|
||||
mut i := 0
|
||||
$if test {
|
||||
i++
|
||||
}
|
||||
$if !test {
|
||||
i--
|
||||
}
|
||||
assert i == 1
|
||||
}
|
Loading…
Reference in New Issue
Block a user