diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index ce84dbf390..a61d662bad 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -3758,10 +3758,6 @@ pub fn (mut c Checker) return_stmt(mut node ast.Return) { if !c.check_types(got_typ, exp_type) { got_typ_sym := c.table.get_type_symbol(got_typ) mut exp_typ_sym := c.table.get_type_symbol(exp_type) - pos := node.exprs[i].position() - if node.exprs[i].is_auto_deref_var() { - continue - } if exp_typ_sym.kind == .interface_ { if c.type_implements(got_typ, exp_type, node.pos) { if !got_typ.is_ptr() && !got_typ.is_pointer() && got_typ_sym.kind != .interface_ @@ -3771,6 +3767,7 @@ pub fn (mut c Checker) return_stmt(mut node ast.Return) { } continue } + pos := node.exprs[i].position() c.error('cannot use `$got_typ_sym.name` as type `${c.table.type_to_str(exp_type)}` in return argument', pos) } diff --git a/vlib/v/checker/tests/mut_receiver_wrong_return_type.out b/vlib/v/checker/tests/mut_receiver_wrong_return_type.out new file mode 100644 index 0000000000..3524822d3c --- /dev/null +++ b/vlib/v/checker/tests/mut_receiver_wrong_return_type.out @@ -0,0 +1,13 @@ +vlib/v/checker/tests/mut_receiver_wrong_return_type.vv:4:9: error: cannot use `Test` as type `?int` in return argument + 2 | + 3 | fn (mut test Test) test() ?int { + 4 | return test + | ~~~~ + 5 | } + 6 | +vlib/v/checker/tests/mut_receiver_wrong_return_type.vv:8:9: error: cannot use `Test` as type `int` in return argument + 6 | + 7 | fn (mut test Test) test2() int { + 8 | return test + | ~~~~ + 9 | } diff --git a/vlib/v/checker/tests/mut_receiver_wrong_return_type.vv b/vlib/v/checker/tests/mut_receiver_wrong_return_type.vv new file mode 100644 index 0000000000..e223907ecb --- /dev/null +++ b/vlib/v/checker/tests/mut_receiver_wrong_return_type.vv @@ -0,0 +1,9 @@ +struct Test {} + +fn (mut test Test) test() ?int { + return test +} + +fn (mut test Test) test2() int { + return test +}