Skip to content

Commit 36470fe

Browse files
authored
parser: fix parsing of cgen.v, in normal mode, when the table is empty (no files in builtin are preparsed) (fix #20606) (#20611)
1 parent ec21663 commit 36470fe

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

vlib/v/parser/parser.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2218,7 +2218,7 @@ fn (mut p Parser) parse_multi_expr(is_top_level bool) ast.Stmt {
22182218
} else if !p.pref.translated && !p.is_translated && !p.pref.is_fmt && !p.pref.is_vet
22192219
&& tok.kind !in [.key_if, .key_match, .key_lock, .key_rlock, .key_select] {
22202220
for node in left {
2221-
if (is_top_level || p.tok.kind != .rcbr)
2221+
if (is_top_level || p.tok.kind !in [.comment, .rcbr])
22222222
&& node !in [ast.CallExpr, ast.PostfixExpr, ast.ComptimeCall, ast.SelectorExpr, ast.DumpExpr] {
22232223
is_complex_infix_expr := node is ast.InfixExpr
22242224
&& node.op in [.left_shift, .right_shift, .unsigned_right_shift, .arrow]

vlib/v/parser/v_parser_test.v

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import v.gen.c
66
import v.checker
77
import v.pref
88
import term
9+
import os
910

1011
fn test_eval() {
1112
/*
@@ -264,6 +265,42 @@ fn test_fn_is_html_open_tag() {
264265
assert b == false
265266
}
266267

268+
fn scan_v(mut files []string, path string) ! {
269+
for i in os.ls(path)! {
270+
p := os.join_path(path, i)
271+
if os.is_file(p) {
272+
if i.ends_with('.v') && !i.contains_any_substr(['_test.', 'test_', 'tests_']) {
273+
files << p
274+
}
275+
} else {
276+
if !i.starts_with('test') && !i.ends_with('_tests') && !i.ends_with('builtin') {
277+
scan_v(mut files, p)!
278+
}
279+
}
280+
}
281+
}
282+
283+
fn parse(output_mode pref.OutputMode) ! {
284+
mut pref_ := pref.new_preferences()
285+
pref_.output_mode = output_mode
286+
mut files := []string{}
287+
scan_v(mut files, pref_.vlib)!
288+
scan_v(mut files, os.join_path(pref_.vroot, 'cmd'))!
289+
for f in files {
290+
table := ast.new_table()
291+
p := parse_file(f, table, .parse_comments, pref_)
292+
assert isnil(p) == false
293+
}
294+
}
295+
296+
fn test_parse_with_silent() {
297+
parse(.silent)!
298+
}
299+
300+
fn test_parse_with_stdout() {
301+
parse(.stdout)!
302+
}
303+
267304
// For issue #15516
268305
fn test_anon_struct() {
269306
}

0 commit comments

Comments
 (0)