Skip to content

Sema: fix switch loop inline capture - #24792

Closed
Justus2308 wants to merge 1 commit into
ziglang:masterfrom
Justus2308:switch-loop-inline
Closed

Justus2308 wants to merge 1 commit into
ziglang:masterfrom
Justus2308:switch-loop-inline

Conversation

@Justus2308

Copy link
Copy Markdown
Member

Resolves #24789

Fixes a premature load of operand_alloc in SwitchProngAnalysis.analyzeCapture which is undefined if no non-inline captures occur by making it .none instead and checking for that case. If it is .none and a capture occurs it must be inline and inline_case_capture is now instantly resolved and returned. The special case here are unions which still need an alloc to store their payload in even if all captures are inline. They now unconditionally get an operand_alloc.

Fixes a premature load of `operand_alloc` in `SwitchProngAnalysis.analyzeCapture`
which is `undefined` if no non-inline captures occur by making it `.none` instead
and checking for that case. If it is `.none` and a capture occurs it must be `inline`
and `inline_case_capture` is now instantly resolved and returned.
The special case here are unions which still need an alloc to store their payload in
even if all captures are `inline`. They now unconditionally get an `operand_alloc`.
@Rexicon226

Copy link
Copy Markdown
Contributor

I think the correct fix looks something like: Rexicon226@6aff7ce.

I honestly completely forgot that I had even made these fixes. I believe the reason I hadn't opened a PR was that, in discussion with @mlugg, we wanted to pursue making x => |_| { ... an error, similar to how x => |foo, _| is an error. The only kinda use case is that it forces captures to peer-resolve the payload when you have multiple cases in a tagged union, although that doesn't seem like a very strong use case to me.

@Justus2308

Copy link
Copy Markdown
Member Author

Ah that looks more sensible thanks! Yeah I think making it an error makes a lot of sense here especially since capturing the value isn't mandatory anyway

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.

Combining labeled switch and inline switch prongs leads to compile error

2 participants