Skip to content

checker: Allow explicit sumtype to option casts#25812

Merged
spytheman merged 3 commits into
vlang:masterfrom
imperivox:master
Nov 23, 2025
Merged

checker: Allow explicit sumtype to option casts#25812
spytheman merged 3 commits into
vlang:masterfrom
imperivox:master

Conversation

@imperivox

Copy link
Copy Markdown
Contributor

This fixes #25796 by allowing explicit casts from a sum type T to its option type ?T, just like with non-sum types.
Before this, code like ?SumType(SumType(u16(0))) failed because SumType -> ?SumType wasn’t allowed.

The fix adds a check that lets you cast to ?T when the value is exactly type T, even if T is a sum type.

@spytheman spytheman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Excellent work.
Thank you @imperivox 🙇🏻 .

@spytheman

Copy link
Copy Markdown
Contributor

@imperivox you have to also run v fmt -w file.v for the changed files, to make sure they are formatted, commit the result, and push to update the PR, to pass the CI.

@imperivox imperivox requested a review from spytheman November 23, 2025 10:14
@imperivox

Copy link
Copy Markdown
Contributor Author

It should be good now

@spytheman spytheman merged commit b17ac33 into vlang:master Nov 23, 2025
85 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.

Cannot cast SumType to ?SumType

2 participants