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

cgen: fix method call checking against none #20717

Merged
merged 1 commit into from
Feb 3, 2024

Conversation

felipensp
Copy link
Member

@felipensp felipensp commented Feb 2, 2024

Fix #20711

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'))
}

@felipensp felipensp marked this pull request as ready for review February 2, 2024 23:47
Copy link
Member

@spytheman spytheman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work.

@spytheman spytheman merged commit f72f1fc into vlang:master Feb 3, 2024
54 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

C error when comparing a Result returned from a function with none
2 participants