Skip to content

Commit 21a473a

Browse files
committed
checker: deref fix 2
1 parent fa62773 commit 21a473a

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

vlib/v/checker/fn.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3898,7 +3898,7 @@ fn (mut c Checker) map_builtin_method_call(mut node ast.CallExpr, left_type_ ast
38983898
// is `array_xxx`, instead of the plain `array` .
38993899
fn (mut c Checker) ensure_same_array_return_type(mut node ast.CallExpr, left_type ast.Type) {
39003900
node.receiver_type = left_type.ref()
3901-
if node.left.is_auto_deref_var() {
3901+
if node.left.is_auto_deref_var() && left_type.nr_muls() > 0 {
39023902
node.return_type = left_type.deref()
39033903
} else {
39043904
node.return_type = node.receiver_type.set_nr_muls(0)

vlib/v/gen/c/cgen.v

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7052,6 +7052,14 @@ fn (mut g Gen) ident(node ast.Ident) {
70527052
if node.obj is ast.Var {
70537053
is_auto_heap = g.resolved_ident_is_auto_heap(node)
70547054
&& (!g.is_assign_lhs || g.assign_op != .decl_assign)
7055+
// When a variable is both auto_heap and auto_deref (e.g. a `mut`
7056+
// parameter of a @[heap] struct), the pointer indirection is
7057+
// already handled by the auto_deref mechanism (-> for selectors,
7058+
// pointer-type tracking in calls). Adding (*(…)) would
7059+
// incorrectly dereference the pointer a second time.
7060+
if is_auto_heap && node.obj.is_auto_deref {
7061+
is_auto_heap = false
7062+
}
70557063
if is_auto_heap && (node.obj.typ.has_flag(.generic)
70567064
|| g.type_has_unresolved_generic_parts(node.obj.typ)) {
70577065
resolved_obj_typ := g.unwrap_generic(node.obj.typ)

0 commit comments

Comments
 (0)