Skip to content

Fix replace *rel = if/case with comprehension branches crashes - #73

Merged
ilyakooo0 merged 1 commit into
masterfrom
push-yrlupltquxtn
Jul 12, 2026
Merged

Fix replace *rel = if/case with comprehension branches crashes#73
ilyakooo0 merged 1 commit into
masterfrom
push-yrlupltquxtn

Conversation

@ilyakooo0

Copy link
Copy Markdown
Owner

Summary

replace *rel = if True then do { x <- *other; yield x } else [] crashed with "source_write expects a Relation, got IO". The desugar pass unwrap_wrappers_mut did not see through If/Case expressions, so a branch containing a comprehension compiled as an IO thunk instead of a relation.

Fix

compile_set_value_expr now recognizes if/case in set-value position. It records spans of do-blocks in result position — walking through wrappers, if branches, and case arms, nested arbitrarily — into a relational_do_spans set. The Do arm of compile_expr consults that set and uses compile_do (relational) instead of compile_io_do.

Tests

2 tests in regress_codegen_fixes.rs: if form (with nested else if and non-comprehension branch) and case form (both arms exercised at runtime).

Verification

cargo test -p knot-compiler --test regress_codegen_fixes
# 29 passed

…shes

replace *rel = if True then do { x <- *other; yield x } else [] crashed
with 'source_write expects a Relation, got IO'. The desugar pass
unwrap_wrappers_mut did not see through If/Case expressions, so a
branch containing a comprehension compiled as an IO thunk instead of
a relation.

Fix: compile_set_value_expr now recognizes if/case in set-value
position. It records spans of do-blocks in result position — walking
through wrappers, if branches, and case arms, nested arbitrarily —
into a relational_do_spans set. The Do arm of compile_expr consults
that set and uses compile_do (relational) instead of compile_io_do.

2 tests in regress_codegen_fixes.rs: if form (with nested else if and
non-comprehension branch) and case form (both arms at runtime).
cargo test -p knot-compiler --test regress_codegen_fixes: 29 passed.
@ilyakooo0 ilyakooo0 added the bug Something isn't working label Jul 12, 2026
@ilyakooo0
ilyakooo0 merged commit ac81de4 into master Jul 12, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant