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

C error when comparing a Result returned from a function with none #20711

Closed
zeozeozeo opened this issue Feb 2, 2024 · 0 comments · Fixed by #20717
Closed

C error when comparing a Result returned from a function with none #20711

zeozeozeo opened this issue Feb 2, 2024 · 0 comments · Fixed by #20717
Assignees
Labels
Unit: cgen Bugs/feature requests, that are related to the default C generating backend.

Comments

@zeozeozeo
Copy link
Contributor

zeozeozeo commented Feb 2, 2024

V doctor:

V full version: V 0.4.4 5306469.e9320ad
OS: windows, Microsoft Windows 10 Pro v19045 64-bit
Processor: 20 cpus, 64bit, little endian, 

getwd: C:\Users\user\Desktop\Code\leaflang
vexe: C:\Users\user\Desktop\Code\v\v.exe
vexe mtime: 2024-02-02 13:06:41

vroot: OK, value: C:\Users\user\Desktop\Code\v
VMODULES: OK, value: C:\Users\user\.vmodules
VTMP: OK, value: C:\Users\user\AppData\Local\Temp\v_0

Git version: git version 2.42.0.windows.1
Git vroot status: weekly.2024.05-13-ge9320add
.git/config present: true

CC version: Error: 'cc' is not recognized as an internal or external command,

operable program or batch file.


thirdparty/tcc status: thirdparty-windows-amd64 a39eb79b

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

struct Foo {
	x int
}
struct Bar {
	x int
}
type Foobar = Foo | Bar
struct Foobars {
	m map[string]Foobar
}
fn (f &Foobars) find_foobar(name string) ?Foobar {
	return f.m[name] or { return none }
}
fn (mut f Foobars) is_known(name string) bool {
	return f.find_foobar(name) != none
}

fn main() {
	mut foobars := Foobars{
		m: map[string]Foobar{}
	}
	println(foobars.is_known('deadbeef'))
}

What did you expect to see?

false printed to stdout

What did you see instead?

==================
C:/Users/user/AppData/Local/Temp/v_0/test.01HNMYW988S2N72XV6W3GMC4VV.tmp.c:6906: warning: implicit declaration of function 'tcc_backtrace'
C:/Users/user/AppData/Local/Temp/v_0/test.01HNMYW988S2N72XV6W3GMC4VV.tmp.c:13069: error: expected struct or union but not 'struct main__Foobars *'
...
==================
(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

Relevant generated C code:

VV_LOCAL_SYMBOL bool main__Foobars_is_known(main__Foobars* f, string name) {
	main__Foobars_find_foobar(f, name);
	bool _t1 = f.find_foobar(name).state != 2; // here
	return _t1;
}

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.

@felipensp felipensp self-assigned this Feb 2, 2024
@felipensp felipensp added the Unit: cgen Bugs/feature requests, that are related to the default C generating backend. label Feb 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Unit: cgen Bugs/feature requests, that are related to the default C generating backend.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants