1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

checker: add a return *x suggestion, to the error fn ... expects you to return a non reference type ..., but you are returning ... instead

This commit is contained in:
Delyan Angelov 2022-12-02 10:21:19 +02:00
parent f16722596c
commit c77344e0a2
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
3 changed files with 3 additions and 0 deletions

View File

@ -184,6 +184,7 @@ fn (mut c Checker) return_stmt(mut node ast.Return) {
if node.exprs[expr_idxs[i]].is_auto_deref_var() {
continue
}
c.add_error_detail('use `return *pointer` instead of `return pointer`, and just `return value` instead of `return &value`')
c.error('fn `${c.table.cur_fn.name}` expects you to return a non reference type `${c.table.type_to_str(exp_type)}`, but you are returning `${c.table.type_to_str(got_typ)}` instead',
pos)
}

View File

@ -5,3 +5,4 @@ vlib/v/checker/tests/return_ref_as_no_ref_bug.vv:11:9: error: fn `return_not_ref
| ^
12 | id: 1
13 | }
Details: use `return *pointer` instead of `return pointer`, and just `return value` instead of `return &value`

View File

@ -17,3 +17,4 @@ vlib/v/checker/tests/union_unsafe_fields.vv:11:9: error: fn `f` expects you to r
11 | return &u.f
| ^
12 | }
Details: use `return *pointer` instead of `return pointer`, and just `return value` instead of `return &value`