fix(ILO-468): type-check braceless-guard tail value against declared return#772
Merged
Conversation
❌ 1 Tests Failed:
View the top 1 failed test(s) by shortest run time
To view more test analytics, go to the Test Analytics Dashboard |
fbf5012 to
ed6fa34
Compare
…return
A braceless guard `cond expr` early-returns `expr`, but the verifier
only checked the function body's last statement against the declared
return type. When a guard's tail value had the wrong type and was
followed by a type-correct fallback (`pred q:t>b;=q "" 1;false`), the
mismatch slipped through silently — at runtime the guard returned the
literal `1` (number) where `b` (bool) was expected, and downstream HOFs
like `flt` got non-bool predicates and silently produced empty results.
Fix: in `verify_stmt` for `Stmt::Guard { braceless: true, .. }`, compare
the guard body's value type against the enclosing function's declared
return type and emit ILO-T008 on mismatch. The inline-lambda case
(synthetic `__lit_N` function) is covered by the same path.
Adds five regression tests and a row in the SPEC cross-language
gotchas table.
Closes ILO-468
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
ed6fa34 to
46de634
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A braceless guard
cond exprearly-returnsexpr, but the verifier only checked the function body's last statement against the declared return type. When a guard's tail value had the wrong type and was followed by a type-correct fallback, the mismatch slipped through silently.The repro that motivated this:
At runtime
pred ""returned the number1. Passingpredtofltproduced an empty result with zero warnings —fltgot non-bool predicates and silently filtered everything out.Fix
In
verify_stmtforStmt::Guard { braceless: true, .. }, compare the guard body's value type against the enclosing function's declared return type (viaself.functions[func].return_type) and emitILO-T008on mismatch. The inline-lambda case (synthetic__lit_Nfunction) is covered by the same code path.No implicit coercion. Surfaces the mismatch as an error at the guard tail's span.
Changes
src/verify.rs: new check at theStmt::Guardarm; 5 new regression tests.SPEC.md: row in cross-language gotchas table.ai.txt: regenerated from SPEC bybuild.rs.Test plan
cargo test --features cranelift,http,golden --libpasses (3510 tests, 0 failures).ilo468_braceless_guard_tail_wrong_type_named_fnand_inline_lambdafire ILO-T008.ilo468_braceless_guard_tail_matching_type_ok,_negated_matching_type_ok,_number_return_okverify cleanly.ilo checkon the repro confirms a clear diagnostic at the guard tail.Closes ILO-468
🤖 Generated with Claude Code