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 codegen for ifguard indexing array of option #23439

Merged
merged 2 commits into from
Jan 12, 2025

Conversation

felipensp
Copy link
Member

Fix #23438

Copy link

Connected to Huly®: V_0.6-21870

@louis77
Copy link
Contributor

louis77 commented Jan 11, 2025

I took the liberty to check out your PR, it fixes the problem for me. So thank you!

@louis77
Copy link
Contributor

louis77 commented Jan 12, 2025

I just discovered a problem which is probably related to this:

Code: https://play.vlang.io/p/d8791e9d1c

module main

fn make_option() ?string {
	return 'abc'
}

fn main() {
	cols := [make_option()]
	output := cols[0] or { 'unknown' }
	println('I made it ${output}')
}

Output:

I made it Option('abc')

The output should be

I made it abc

This happens only when the unwrapped value came from an array.

@felipensp
Copy link
Member Author

I just discovered a problem which is probably related to this:

Code: https://play.vlang.io/p/d8791e9d1c

module main

fn make_option() ?string {
	return 'abc'
}

fn main() {
	cols := [make_option()]
	output := cols[0] or { 'unknown' }
	println('I made it ${output}')
}

Output:

I made it Option('abc')

The output should be

I made it abc

This happens only when the unwrapped value came from an array.

Can you file separate issue about it?

@felipensp felipensp marked this pull request as ready for review January 12, 2025 00:57
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 5cd2584 into vlang:master Jan 12, 2025
72 checks passed
@felipensp felipensp deleted the fix_ifguard_array_of_option branch January 13, 2025 10:43
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 compiler error when unwrapping Optional in an array
3 participants