Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion vlib/v/checker/fn.v
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 9 additions & 0 deletions vlib/v/checker/tests/surplus_args_with_or_block_err.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
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 {
| ~~~~~~
35 | if config.use_color {
36 | eprintln('Error: export failed')
Details: have ([]main.SimResult, string, main.Config)
want ([]main.SimResult, main.Config)
42 changes: 42 additions & 0 deletions vlib/v/checker/tests/surplus_args_with_or_block_err.vv
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
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')
}
}
}
}
Loading