diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index b8edca6bb1..33cc111eb3 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -7790,17 +7790,21 @@ fn (mut c Checker) fn_decl(mut node ast.FnDecl) { return_sym := c.table.get_type_symbol(node.return_type) if return_sym.info is ast.MultiReturn { for multi_type in return_sym.info.types { + multi_sym := c.table.get_type_symbol(multi_type) if multi_type == ast.error_type { c.error('type `IError` cannot be used in multi-return, return an option instead', node.return_type_pos) } else if multi_type.has_flag(.optional) { c.error('option cannot be used in multi-return, return an option instead', node.return_type_pos) + } else if multi_sym.kind == .array_fixed { + c.error('fixed array cannot be used in multi-return', node.return_type_pos) } } + } else if return_sym.kind == .array_fixed { + c.error('fixed array cannot be returned by function', node.return_type_pos) } - } - if node.return_type == ast.void_type { + } else { for mut a in node.attrs { if a.kind == .comptime_define { c.evaluate_once_comptime_if_attribute(mut a) diff --git a/vlib/v/checker/tests/return_fixed_array.out b/vlib/v/checker/tests/return_fixed_array.out new file mode 100644 index 0000000000..3ac7df0fe6 --- /dev/null +++ b/vlib/v/checker/tests/return_fixed_array.out @@ -0,0 +1,12 @@ +vlib/v/checker/tests/return_fixed_array.vv:1:25: error: fixed array cannot be returned by function + 1 | fn return_fixed_array() [3]int { + | ~~~~~~ + 2 | return [1, 2, 3]! + 3 | } +vlib/v/checker/tests/return_fixed_array.vv:5:41: error: fixed array cannot be used in multi-return + 3 | } + 4 | + 5 | fn return_fixed_array_in_multi_return() ([3]int, [3]int) { + | ~~~~~~~~~~~~~~~~ + 6 | return [1, 2, 3]!, [4, 5, 6]! + 7 | } diff --git a/vlib/v/checker/tests/return_fixed_array.vv b/vlib/v/checker/tests/return_fixed_array.vv new file mode 100644 index 0000000000..dc24da155c --- /dev/null +++ b/vlib/v/checker/tests/return_fixed_array.vv @@ -0,0 +1,7 @@ +fn return_fixed_array() [3]int { + return [1, 2, 3]! +} + +fn return_fixed_array_in_multi_return() ([3]int, [3]int) { + return [1, 2, 3]!, [4, 5, 6]! +}