mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: check error for returning aliases of fixed array (#14349)
This commit is contained in:
parent
9e09b709e3
commit
606d8cfaca
@ -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)
|
||||
|
14
vlib/v/checker/tests/return_aliases_of_fixed_array.out
Normal file
14
vlib/v/checker/tests/return_aliases_of_fixed_array.out
Normal file
@ -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 | }
|
14
vlib/v/checker/tests/return_aliases_of_fixed_array.vv
Normal file
14
vlib/v/checker/tests/return_aliases_of_fixed_array.vv
Normal file
@ -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]!]!)
|
||||
}
|
Loading…
Reference in New Issue
Block a user