mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parent
1dcec62c19
commit
4f532c0830
@ -229,8 +229,9 @@ fn (mut c Checker) return_stmt(mut node ast.Return) {
|
|||||||
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)
|
||||||
}
|
}
|
||||||
if (exp_type.is_ptr() || exp_type.is_pointer())
|
unaliased_got_typ := c.table.unaliased_type(got_typ)
|
||||||
&& (!got_typ.is_ptr() && !got_typ.is_pointer()) && got_typ != ast.int_literal_type
|
if (exp_type.is_ptr() || exp_type.is_pointer()) && !got_typ.is_real_pointer()
|
||||||
|
&& !unaliased_got_typ.is_real_pointer() && got_typ != ast.int_literal_type
|
||||||
&& !c.pref.translated && !c.file.is_translated {
|
&& !c.pref.translated && !c.file.is_translated {
|
||||||
pos := node.exprs[expr_idxs[i]].pos()
|
pos := node.exprs[expr_idxs[i]].pos()
|
||||||
if node.exprs[expr_idxs[i]].is_auto_deref_var() {
|
if node.exprs[expr_idxs[i]].is_auto_deref_var() {
|
||||||
|
16
vlib/v/tests/fn_return_alias_of_ptr_test.v
Normal file
16
vlib/v/tests/fn_return_alias_of_ptr_test.v
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
type HANDLE = voidptr
|
||||||
|
|
||||||
|
struct ExampleStruct {
|
||||||
|
handle HANDLE
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_ptr(arg ExampleStruct) voidptr {
|
||||||
|
return arg.handle
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_fn_return_alias_of_ptr() {
|
||||||
|
h := ExampleStruct{}
|
||||||
|
r := get_ptr(h)
|
||||||
|
println(r)
|
||||||
|
assert r == unsafe { nil }
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user