Skip to content

checker: validate or-block defaults before outer casts - #27059

Merged
medvednikov merged 1 commit into
vlang:masterfrom
GGRei:repair/27054-or-block-cast
May 2, 2026
Merged

medvednikov merged 1 commit into
vlang:masterfrom
GGRei:repair/27054-or-block-cast

Conversation

@GGRei

@GGRei GGRei commented May 2, 2026

Copy link
Copy Markdown
Contributor

Fix #27054

This patch fixes or-block fallback validation when an Option/Result expression is used inside an outer cast. The checker now validates the or-block default against the original unwrapped payload type, instead of letting the outer cast type leak into the fallback check. This covers both call expressions like int(result_f64() or { 3.0 }) and selector expressions like int(holder.x or { 3.0 }), with tests for literals, aliases, generics, parent return, none, error(...), and invalid fallback types.

Explicitly out of scope: h.x or {} and h.x or { side_effect }, because those are rejected earlier by selector_expr. Supporting that form would be a separate language/checker decision about whether selector or {} blocks without a value should be allowed, and that is not something I should decide in this patch. Also, struct fields cannot currently store Result types (!T), so there is no r !f64 selector-field test.

@medvednikov
medvednikov merged commit 4ad633a into vlang:master May 2, 2026
71 of 91 checks passed
@GGRei
GGRei deleted the repair/27054-or-block-cast branch June 7, 2026 05:04
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.

error: wrong return type f64 in the or {} block, expected f64

2 participants