Assert codegen#196
Conversation
There was a problem hiding this comment.
Pull request overview
Implements WebAssembly codegen for the assert statement, replacing the previous todo!() panic with a trap-on-false sequence (<cond>; i32.eqz; if; unreachable; end). Also improves the type-checker diagnostic for assert <non-bool> by introducing a dedicated TypeMismatchContext::Assert and refactoring the shared bool-condition validation into a helper that points at the offending expression rather than the enclosing statement.
Changes:
- Lower
Stmt::AssertinCompiler::lower_statementvia a newlower_assert_statementhelper guarded bycov_mark. - Add
TypeMismatchContext::Assertand extract avalidate_bool_expressionhelper to deduplicate bool checks acrossif/loop/assert, with error location anchored on the expression. - Add golden + execution + Soroban-compat tests and extend type-checker coverage tests for assert.
Reviewed changes
Copilot reviewed 9 out of 10 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| core/wasm-codegen/src/compiler.rs | Implements lower_assert_statement and wires Stmt::Assert to it. |
| core/type-checker/src/type_checker.rs | Refactors bool-condition checks to a shared helper; routes Assert through it with Assert context. |
| core/type-checker/src/errors.rs | Adds TypeMismatchContext::Assert variant and Display branch; extends Display tests. |
| tests/src/codegen/wasm/base.rs | Adds golden, runtime trap/ok, Soroban-accept, and regen-fixture tests for assert. |
| tests/src/codegen/wasm/negative.rs | Removes obsolete "assert is unimplemented" negative tests. |
| tests/src/type_checker/coverage.rs | Updates if/assert non-bool diagnostics expectations and adds positive/negative assert cases. |
| tests/test_data/codegen/wasm/base/assert/assert.inf | New .inf fixture covering 12 assert scenarios. |
| tests/test_data/codegen/wasm/base/assert/assert.wat | Expected WAT for the fixture. |
| CHANGELOG.md | Documents the codegen and type-checker changes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Closes #195