Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

foo(mut a) generates invalid c code, for fn foo(mut baz ?&Abc) {, and mut a := ?Abc{} #18818

Open
spytheman opened this issue Jul 8, 2023 · 0 comments · May be fixed by #19100
Open

foo(mut a) generates invalid c code, for fn foo(mut baz ?&Abc) {, and mut a := ?Abc{} #18818

spytheman opened this issue Jul 8, 2023 · 0 comments · May be fixed by #19100
Assignees
Labels
Bug This tag is applied to issues which reports bugs. Option Type Bugs/feature requests, that are related to `?Type`. Unit: cgen Bugs/feature requests, that are related to the default C generating backend. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general.

Comments

@spytheman
Copy link
Member

V doctor:

V full version: V 0.4.0 ad1d5e7.8cbbb44
OS: linux, Ubuntu 20.04.6 LTS
Processor: 4 cpus, 64bit, little endian, Intel(R) Core(TM) i3-3225 CPU @ 3.30GHz

getwd: /v/vnew
vexe: /v/vnew/v
vexe mtime: 2023-07-07 18:17:50

vroot: OK, value: /v/vnew
VMODULES: OK, value: /home/delian/.vmodules
VTMP: OK, value: /tmp/v_1000

Git version: git version 2.41.0
Git vroot status: weekly.2023.27-35-g17b57622
.git/config present: true

CC version: cc (Ubuntu 10.3.0-1ubuntu1~20.04) 10.3.0
thirdparty/tcc status: thirdparty-linux-amd64 12f392c3

What did you do?
v -g -o vdbg cmd/v && vdbg i.v

struct Abc {
}

fn foo(mut baz ?&Abc) {
	if num := baz {
		println(num)
	}
}

fn main() {
	mut a := ?Abc{}
	dump(a)
	foo(mut a)
}

What did you expect to see?

a compiled program

What did you see instead?

==================
/tmp/v_1000/i.11048463194684825626.tmp.c:12600: error: cannot convert 'struct _option_main__Abc' to 'struct _option_main__Abc_ptr'
...
==================
(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`.

https://github.com/vlang/v/issues/new/choose

You can also use #help on Discord: https://discord.gg/vlang

Note that with mut a := &?Abc{}, the code compiles:

struct Abc {
}

fn foo(mut baz ?&Abc) {
	dump(@METHOD)
	if num := baz {
		println(num)
	}
}

fn main() {
	mut a := &?Abc{}
	dump(a)
	foo(mut a)
}
@spytheman spytheman added Bug This tag is applied to issues which reports bugs. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general. Unit: cgen Bugs/feature requests, that are related to the default C generating backend. Option Type Bugs/feature requests, that are related to `?Type`. labels Jul 8, 2023
@felipensp felipensp self-assigned this Aug 8, 2023
@felipensp felipensp linked a pull request Aug 9, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs. Option Type Bugs/feature requests, that are related to `?Type`. Unit: cgen Bugs/feature requests, that are related to the default C generating backend. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants