Skip to content

checker,cgen,type_resolver: prevent stale type cast on comptime for, …#25784

Merged
spytheman merged 1 commit into
vlang:masterfrom
dy-tea:comptime-value
Nov 20, 2025
Merged

checker,cgen,type_resolver: prevent stale type cast on comptime for, …#25784
spytheman merged 1 commit into
vlang:masterfrom
dy-tea:comptime-value

Conversation

@dy-tea

@dy-tea dy-tea commented Nov 20, 2025

Copy link
Copy Markdown
Member

Fixes #25781.

I really hope I fixed all the issues with comptime for at this point. There was some issues with stale type references being used in assignment inside comptime for, value != none was also not casting value to a some type and $if v is string would evaluate to true on all iterations inside the loop in the test (due to the stale reference).

I added multiple cases of the below code snippet:

mut idx_str := comptime_branch_context_str + '|id=${branch.id}|'
if c.comptime.inside_comptime_for && c.comptime.comptime_for_field_var != '' {
	idx_str += '|field_type=${c.comptime.comptime_for_field_type}|'
}

Maybe might want to make it into a function.

@spytheman

Copy link
Copy Markdown
Contributor

A method on comptime will be best imho, to avoid passing in .inside_comptime_for. .comptime_for_field_var and .comptime_for_field_type.

@spytheman spytheman merged commit 20aefee into vlang:master Nov 20, 2025
84 checks passed
@spytheman

Copy link
Copy Markdown
Contributor

Excellent work, thanks @dy-tea 🙇🏻 .

@jorgeluismireles

Copy link
Copy Markdown
Contributor

Thanks a lot @dy-tea this last PR permits to process the unwrapped option values finally. I had to call inside my encoder a process function where inside update a values map and now is working. If instead I reused a process function didn't work. I think is too complex the validation inside those comptime code to request any further. Thanks also for your fix for comptime struct fields as fixed array they are working too. Your fixes were necessary though not sufficient for json2 as is to include fields as options and fixed array but is another thing to look next. Thanks.

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.

comptime: struct field option type/value prints ok, but can't be passed to process functions. Continuation PR 25773

3 participants