v icon indicating copy to clipboard operation
v copied to clipboard

struct reference mutable function argument builder problem

Open Eliyaan opened this issue 1 year ago • 0 comments

Describe the bug

When the struct reference is a mutable function argument it outputs a builder error and a warning.

Reproduction Steps


@[heap]
struct Client {
mut:
  next &Client
  prev &Client

}

fn init_vm(mut head &Client) {
  	for c := head; c == unsafe{nil}; c = c.next { 

	}
}

fn main() {
	mut head := &Client(unsafe{nil})
   	init_vm(mut head)
}

@[heap]
struct Client {
mut:
  next &Client
  prev &Client

}

fn init_vm(mut head &Client) {
  	for c := head; c; c = c.next { 

	}
}

fn main() {
	mut head := &Client(unsafe{nil})
   	init_vm(mut head)
}

Expected Behavior

It not to output a builder error nor a warning.

Current Behavior

issue.v:11:39: warning: cannot assign a reference to a value (this will be an error soon) left=Client false right=Client true ptr=true
    9 | 
   10 | fn init_vm(mut head &Client) {
   11 |       for c := head; c == unsafe{nil}; c = c.next { 
      |                                          ^
   12 | 
   13 |     }
==================
/tmp/v_1000/issue.01HV8TCY7TQM1F0E8ZW6X6ETY7.tmp.c:13024: error: cannot convert 'struct main__Client' to 'unsigned long'
...
==================
(Use `v -cg` to print the entire error message)

builder error

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.5 423c39c

Environment details (OS name and version, etc.)

V full version: V 0.4.5 294f7e4.423c39c OS: linux, Linux version 6.6.13-200.fc39.x86_64 (mockbuild@72f11b2996ed4699b0f705186172808f) (gcc (GCC) 13.2.1 20231205 (Red Hat 13.2.1-6), GNU ld version 2.40-13.fc39) #1 SMP PREEMPT_DYNAMIC Sat Jan 20 18:03:28 UTC 2024 Processor: 4 cpus, 64bit, little endian, Intel(R) Pentium(R) Gold 7505 @ 2.00GHz

[!NOTE] You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote. Other reactions and those to comments will not be taken into account.

Eliyaan avatar Apr 12 '24 09:04 Eliyaan