From 3e2860ace7589998de3196b9684ab1402566d7bd Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 25 Feb 2026 20:35:41 +0000 Subject: [PATCH 1/2] checker: fix panic on wrong arg count with or-block containing if-expr When `check_expected_arg_count` detected wrong argument count and returned early from `fn_call`, `node.return_type` was never set (staying as 0). Back in `call_expr`, the or-block was still processed using this zero type, and when `if_expr` inside the or-block called `table.type_kind(0)` -> `table.sym(0)`, the compiler panicked with "table.sym: invalid type (typ=ast.Type(0x0 = 0) idx=0)". Fix: set `node.return_type = func.return_type` before the early return so the or-block processes correctly even after an argument count error. https://claude.ai/code/session_01RB9tJf3t9GEuuqcw1inq8k --- vlib/v/checker/fn.v | 5 ++- .../tests/surplus_args_with_or_block_err.out | 9 +++++ .../tests/surplus_args_with_or_block_err.vv | 39 +++++++++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 vlib/v/checker/tests/surplus_args_with_or_block_err.out create mode 100644 vlib/v/checker/tests/surplus_args_with_or_block_err.vv diff --git a/vlib/v/checker/fn.v b/vlib/v/checker/fn.v index b1338fc25fb294..5dde76d4b91e45 100644 --- a/vlib/v/checker/fn.v +++ b/vlib/v/checker/fn.v @@ -1517,7 +1517,10 @@ fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool) ast. } } } - c.check_expected_arg_count(mut node, func) or { return func.return_type } + c.check_expected_arg_count(mut node, func) or { + node.return_type = func.return_type + return func.return_type + } } // println / eprintln / panic can print anything if args_len > 0 && fn_name in print_everything_fns { diff --git a/vlib/v/checker/tests/surplus_args_with_or_block_err.out b/vlib/v/checker/tests/surplus_args_with_or_block_err.out new file mode 100644 index 00000000000000..06c30874414a3f --- /dev/null +++ b/vlib/v/checker/tests/surplus_args_with_or_block_err.out @@ -0,0 +1,9 @@ +vlib/v/checker/tests/surplus_args_with_or_block_err.vv:31:47: error: expected 2 arguments, but got 3 + 29 | + 30 | if config.output_file != '' { + 31 | export_results(results, config.output_file, config) or { + | ~~~~~~ + 32 | if config.use_color { + 33 | eprintln('Error: export failed') +Details: have ([]main.SimResult, string, main.Config) + want ([]main.SimResult, main.Config) diff --git a/vlib/v/checker/tests/surplus_args_with_or_block_err.vv b/vlib/v/checker/tests/surplus_args_with_or_block_err.vv new file mode 100644 index 00000000000000..cf85d4d79dc0b8 --- /dev/null +++ b/vlib/v/checker/tests/surplus_args_with_or_block_err.vv @@ -0,0 +1,39 @@ +struct Config { + use_color bool + output_file string +} + +struct SimResult { + filename string + accuracy f64 +} + +fn export_results(results []SimResult, config Config) ! { + if config.output_file == '' { + return + } + println('Exporting to ${config.output_file}') +} + +fn run_simulation(config Config) []SimResult { + return [SimResult{filename: 'test', accuracy: 0.9}] +} + +fn main() { + mut config := Config{ + use_color: true + output_file: 'results.json' + } + + results := run_simulation(config) + + if config.output_file != '' { + export_results(results, config.output_file, config) or { + if config.use_color { + eprintln('Error: export failed') + } else { + eprintln('Error') + } + } + } +} From 9f171b1bcabe1d45bf580905dbc4e716fa300588 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 25 Feb 2026 20:50:37 +0000 Subject: [PATCH 2/2] checker: fmt test file and update expected output https://claude.ai/code/session_01RB9tJf3t9GEuuqcw1inq8k --- .../checker/tests/surplus_args_with_or_block_err.out | 12 ++++++------ .../checker/tests/surplus_args_with_or_block_err.vv | 5 ++++- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/vlib/v/checker/tests/surplus_args_with_or_block_err.out b/vlib/v/checker/tests/surplus_args_with_or_block_err.out index 06c30874414a3f..f0a7ccfd73acf9 100644 --- a/vlib/v/checker/tests/surplus_args_with_or_block_err.out +++ b/vlib/v/checker/tests/surplus_args_with_or_block_err.out @@ -1,9 +1,9 @@ -vlib/v/checker/tests/surplus_args_with_or_block_err.vv:31:47: error: expected 2 arguments, but got 3 - 29 | - 30 | if config.output_file != '' { - 31 | export_results(results, config.output_file, config) or { +vlib/v/checker/tests/surplus_args_with_or_block_err.vv:34:47: error: expected 2 arguments, but got 3 + 32 | + 33 | if config.output_file != '' { + 34 | export_results(results, config.output_file, config) or { | ~~~~~~ - 32 | if config.use_color { - 33 | eprintln('Error: export failed') + 35 | if config.use_color { + 36 | eprintln('Error: export failed') Details: have ([]main.SimResult, string, main.Config) want ([]main.SimResult, main.Config) diff --git a/vlib/v/checker/tests/surplus_args_with_or_block_err.vv b/vlib/v/checker/tests/surplus_args_with_or_block_err.vv index cf85d4d79dc0b8..e1c05d04b26b8c 100644 --- a/vlib/v/checker/tests/surplus_args_with_or_block_err.vv +++ b/vlib/v/checker/tests/surplus_args_with_or_block_err.vv @@ -16,7 +16,10 @@ fn export_results(results []SimResult, config Config) ! { } fn run_simulation(config Config) []SimResult { - return [SimResult{filename: 'test', accuracy: 0.9}] + return [SimResult{ + filename: 'test' + accuracy: 0.9 + }] } fn main() {