v icon indicating copy to clipboard operation
v copied to clipboard

c-gen error when working with options

Open Heptalon opened this issue 2 years ago • 1 comments

Describe the bug

The code shown below fails to compile.

Expected Behavior

I would expect the code to ompile w/o an error.

Current Behavior

==================
C:/Users/Heptalon/AppData/Local/Temp/v_0/main.exe.4265349337897149812.tmp.c:7577: warning: cast between pointer and integer of different size
C:/Users/Heptalon/AppData/Local/Temp/v_0/main.exe.4265349337897149812.tmp.c:12455: error: cannot convert 'struct _option_int' to 'int'
...
==================
(Use `v -cg` to print the entire error message)
builder error: 
==================
C error. This should never happen.
This is a compiler bug, please report it using `v bug file.v`.

Reproduction Steps

module main


fn main() {
	int_opt := ?int(1)

	if i := int_opt {
		println(i)
	}
}

fn int_to_string(i ?int) ?string{
	return i?.str()
}

Possible Solution

No response

Additional Information/Context

The code successfully runs if either the content of main is removed or the function definition int_to_string.

V version

V 0.3.3 2597efa

Environment details (OS name and version, etc.)

Windows 10 Pro

Heptalon avatar Mar 07 '23 21:03 Heptalon

I only get the error (not the warning) on Linux, but it is indeed happening in latest V.

JalonSolov avatar Mar 07 '23 21:03 JalonSolov