Skip to content

Commit 148bb31

Browse files
authored
v.parser: allow for if x { $if y {} } else {}, fix #10243 (#10294)
1 parent 9850520 commit 148bb31

File tree

3 files changed

+55
-11
lines changed

3 files changed

+55
-11
lines changed

vlib/v/parser/if_match.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ fn (mut p Parser) if_expr(is_comptime bool) ast.IfExpr {
134134
p.error('use `\$else` instead of `else` in compile-time `if` branches')
135135
return ast.IfExpr{}
136136
}
137-
if p.peek_tok.kind == .key_else {
137+
if p.tok.kind != .rcbr && p.peek_tok.kind == .key_else {
138138
p.check(.dollar)
139139
}
140140
}

vlib/v/tests/comptime_if_test.v

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
fn test_comptime_if_test() {
2+
mut i := 0
3+
$if test {
4+
i++
5+
}
6+
$if !test {
7+
i--
8+
}
9+
assert i == 1
10+
}
11+
12+
fn test_comptime_if_parsing_in_combination_with_ordinary_if_1() {
13+
if true {
14+
$if debug {
15+
println('debug')
16+
}
17+
} else {
18+
assert false
19+
}
20+
assert true
21+
}
22+
23+
fn test_comptime_if_parsing_in_combination_with_ordinary_if_2() {
24+
if true {
25+
if true {
26+
$if debug {
27+
println('debug')
28+
}
29+
} else {
30+
assert false
31+
}
32+
} else {
33+
assert false
34+
}
35+
assert true
36+
}
37+
38+
fn test_comptime_if_parsing_in_combination_with_ordinary_if_3() {
39+
println(@LINE)
40+
$if true {
41+
println(@LINE)
42+
$if true {
43+
println(@LINE)
44+
$if debug {
45+
println('debug')
46+
}
47+
} $else {
48+
assert false
49+
}
50+
} $else {
51+
assert false
52+
}
53+
assert true
54+
}

vlib/v/tests/comptime_if_test_support_test.v

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)