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 option sumtype with option variant #23656

Merged
merged 1 commit into from
Feb 5, 2025

Conversation

felipensp
Copy link
Member

Fix #23653

Copy link

Connected to Huly®: V_0.6-22076

@felipensp felipensp marked this pull request as ready for review February 5, 2025 12:37
@@ -2585,7 +2585,7 @@ struct SumtypeCastingFn {

fn (mut g Gen) get_sumtype_casting_fn(got_ ast.Type, exp_ ast.Type) string {
mut got, exp := got_.idx_type(), exp_.idx_type()
i := int(got) | int(u32(exp) << 17) | int(u32(exp_.has_flag(.option)) << 16)
i := int(got) | int(u32(exp) << 18) | int(u32(exp_.has_flag(.option)) << 17) | int(u32(got_.has_flag(.option)) << 16)
Copy link
Member

Choose a reason for hiding this comment

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

I think this should be better commented.

It took me 10 minutes to figure out what it actually does, and why the shifts are as they are.

Copy link
Member

Choose a reason for hiding this comment

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

Given that we have:

vlib/v/gen/c/cgen.v:194:sumtype_definitions       map[int]bool    // `_TypeA_to_sumtype_TypeB()` fns that have been generated

can we just make the map map[u64]bool instead?

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 4c8c892 into vlang:master Feb 5, 2025
72 checks passed
@felipensp felipensp deleted the fix_option_sumtype_casting branch February 5, 2025 17:18
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.

CGEN error with sum type and optional string
2 participants