Skip to content

Commit 539f2bc

Browse files
authored
v3: support .vv inputs and comma diagnostics (#28155)
1 parent 52d25fa commit 539f2bc

6 files changed

Lines changed: 48 additions & 2 deletions

File tree

vlib/v3/driver/driver.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6372,7 +6372,7 @@ fn v3_profile_optional_arg_value(args []string, idx int, command_seen bool) (str
63726372
return '-', false
63736373
}
63746374
if !command_seen && (next in ['run', 'build', 'test', 'doc'] || next.ends_with('.v')
6375-
|| next.ends_with('.vsh') || os.is_dir(next)
6375+
|| next.ends_with('.vv') || next.ends_with('.vsh') || os.is_dir(next)
63766376
|| !v3_has_following_positional_arg(args, idx + 2)) {
63776377
return '-', false
63786378
}

vlib/v3/driver/implicit_import_test.v

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ fn test_default_bin_file_strips_backend_source_extension() {
1010
assert default_bin_file_for_input('foo.js.v') == 'foo'
1111
assert default_bin_file_for_input('foo.wasm.v') == 'foo'
1212
assert default_bin_file_for_input('foo.v') == 'foo'
13+
assert default_bin_file_for_input('foo.vv') == 'foo'
14+
}
15+
16+
fn test_profile_optional_arg_recognizes_vv_source() {
17+
value, consumed := v3_profile_optional_arg_value(['-profile', 'fixture.vv', '-o', 'out'], 0,
18+
false)
19+
assert value == '-'
20+
assert !consumed
1321
}
1422

1523
fn test_default_bin_file_uses_safe_hidden_source_name() {

vlib/v3/parser/parser.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ pub fn (mut p Parser) parse_into(path string) {
305305
if !p.prefs.supports_inline_asm {
306306
p.precollect_unsupported_inline_asm_guards(stable_src, p.prefs.target.arch)
307307
}
308-
if path.ends_with('.v') {
308+
if path.ends_with('.v') || path.ends_with('.vv') {
309309
p.parsed_v_files++
310310
p.parsed_v_file_paths << path
311311
} else if path.ends_with('.vh') {

vlib/v3/tests/parser_regression_test.v

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,18 @@ fn parse_parser_regression_backend_diagnostics(name string, source string, backe
4444
return p.diagnostics
4545
}
4646

47+
fn test_vv_input_is_counted_as_v_source() {
48+
path := os.join_path(os.temp_dir(), 'v3_parser_source_count_${os.getpid()}.vv')
49+
os.write_file(path, 'fn main() {}\n') or { panic(err) }
50+
defer {
51+
os.rm(path) or {}
52+
}
53+
mut p := parser.Parser.new(pref.new_preferences())
54+
p.parse_into(path)
55+
assert p.parsed_v_files == 1
56+
assert p.parsed_v_file_paths == [path]
57+
}
58+
4759
// interface_method_param_types supports interface method param types handling for v3 tests.
4860
fn interface_method_param_types(a &flat.FlatAst, iface string, method string) []string {
4961
for node in a.nodes {

vlib/v3/tests/type_checker_errors_test.v

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,23 @@ fn test_type_checker_reports_core_semantic_errors() {
584584
}, 'main.v', 'cannot append `[]modb.Foo` to `[]moda.Foo`')
585585
}
586586

587+
fn test_vv_input_with_comma_in_decl_assign_is_rejected_without_overwrite() {
588+
v3_bin := build_v3()
589+
source_path := unique_temp_path('comma_in_decl_assign') + '.vv'
590+
default_output := source_path.all_before_last('.vv')
591+
source := 'fn main() {\n\ta := [1, 2, 3]\n\tmut b := a.clone(), a.clone()\n\tprintln(b)\n}\n'
592+
os.write_file(source_path, source) or { panic(err) }
593+
defer {
594+
os.rm(source_path) or {}
595+
os.rm(default_output) or {}
596+
}
597+
result := os.execute('${v3_bin} -nocache ${source_path}')
598+
assert result.exit_code != 0, 'expected compile failure, got success: ${result.output}'
599+
assert result.output.contains('unexpected `,` in expression, use `;` or a new line to separate statements'), result.output
600+
601+
assert (os.read_file(source_path) or { panic(err) }) == source
602+
}
603+
587604
fn test_interface_container_as_cast_requirements() {
588605
v3_bin := build_v3()
589606
run_bad(v3_bin, 'bad_nonempty_interface_as_array_pattern',

vlib/v3/types/checker_comptime.v

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13406,6 +13406,15 @@ fn (mut tc TypeChecker) check_multi_value_list_decl_assign(id flat.NodeId, node
1340613406
if lhs_ids.len == 0 || rhs_count <= 1 {
1340713407
return false
1340813408
}
13409+
if lhs_ids.len == 1 {
13410+
first_rhs_id := tc.multi_assign_rhs_id(node, 0)
13411+
tc.check_node(first_rhs_id)
13412+
unexpected_rhs_id := tc.multi_assign_rhs_id(node, 1)
13413+
tc.record_error(.assignment_mismatch,
13414+
'unexpected `,` in expression, use `;` or a new line to separate statements',
13415+
unexpected_rhs_id)
13416+
return true
13417+
}
1340913418
mut rhs_ids := []flat.NodeId{cap: rhs_count}
1341013419
mut multi_ids := []flat.NodeId{}
1341113420
mut multi_types := []MultiReturn{}

0 commit comments

Comments
 (0)