diff --git a/vlib/v/parser/if_match.v b/vlib/v/parser/if_match.v index 513b4bbe6d..caf103669a 100644 --- a/vlib/v/parser/if_match.v +++ b/vlib/v/parser/if_match.v @@ -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) } } diff --git a/vlib/v/tests/comptime_if_test.v b/vlib/v/tests/comptime_if_test.v new file mode 100644 index 0000000000..4e5d60d0e1 --- /dev/null +++ b/vlib/v/tests/comptime_if_test.v @@ -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 +} diff --git a/vlib/v/tests/comptime_if_test_support_test.v b/vlib/v/tests/comptime_if_test_support_test.v deleted file mode 100644 index 5eaf2bbd7e..0000000000 --- a/vlib/v/tests/comptime_if_test_support_test.v +++ /dev/null @@ -1,10 +0,0 @@ -fn test_comptime_if_test() { - mut i := 0 - $if test { - i++ - } - $if !test { - i-- - } - assert i == 1 -}