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:
parent
f16722596c
commit
c77344e0a2
@ -184,6 +184,7 @@ fn (mut c Checker) return_stmt(mut node ast.Return) {
|
|||||||
if node.exprs[expr_idxs[i]].is_auto_deref_var() {
|
if node.exprs[expr_idxs[i]].is_auto_deref_var() {
|
||||||
continue
|
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',
|
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)
|
pos)
|
||||||
}
|
}
|
||||||
|
@ -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
|
12 | id: 1
|
||||||
13 | }
|
13 | }
|
||||||
|
Details: use `return *pointer` instead of `return pointer`, and just `return value` instead of `return &value`
|
||||||
|
@ -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
|
11 | return &u.f
|
||||||
| ^
|
| ^
|
||||||
12 | }
|
12 | }
|
||||||
|
Details: use `return *pointer` instead of `return pointer`, and just `return value` instead of `return &value`
|
||||||
|
Loading…
Reference in New Issue
Block a user