diff --git a/vlib/v/checker/fn.v b/vlib/v/checker/fn.v index f991b56956..fbcb673487 100644 --- a/vlib/v/checker/fn.v +++ b/vlib/v/checker/fn.v @@ -92,7 +92,7 @@ fn (mut c Checker) fn_decl(mut node ast.FnDecl) { } } } - return_sym := c.table.sym(node.return_type) + return_sym := c.table.final_sym(node.return_type) if return_sym.info is ast.MultiReturn { for multi_type in return_sym.info.types { multi_sym := c.table.sym(multi_type) diff --git a/vlib/v/checker/tests/return_aliases_of_fixed_array.out b/vlib/v/checker/tests/return_aliases_of_fixed_array.out new file mode 100644 index 0000000000..f8ac3c16b0 --- /dev/null +++ b/vlib/v/checker/tests/return_aliases_of_fixed_array.out @@ -0,0 +1,14 @@ +vlib/v/checker/tests/return_aliases_of_fixed_array.vv:8:18: error: fixed array cannot be returned by function + 6 | } + 7 | + 8 | fn (v Mat) foo() Mat { + | ~~~ + 9 | return v + 10 | } +vlib/v/checker/tests/return_aliases_of_fixed_array.vv:12:10: error: fixed array cannot be returned by function + 10 | } + 11 | + 12 | fn bar() Mat { + | ~~~ + 13 | return Mat([[1, 2]!, [3, 4]!]!) + 14 | } diff --git a/vlib/v/checker/tests/return_aliases_of_fixed_array.vv b/vlib/v/checker/tests/return_aliases_of_fixed_array.vv new file mode 100644 index 0000000000..2fe644e92d --- /dev/null +++ b/vlib/v/checker/tests/return_aliases_of_fixed_array.vv @@ -0,0 +1,14 @@ +type Mat = [2][2]int + +fn main() { + a := Mat([[1, 2]!, [3, 4]!]!) + println(a.foo()) +} + +fn (v Mat) foo() Mat { + return v +} + +fn bar() Mat { + return Mat([[1, 2]!, [3, 4]!]!) +}