Skip to content

Assert codegen#196

Merged
0xGeorgii merged 1 commit into
mainfrom
195-assert-keyword-support-in-spec
May 18, 2026
Merged

Assert codegen#196
0xGeorgii merged 1 commit into
mainfrom
195-assert-keyword-support-in-spec

Conversation

@0xGeorgii
Copy link
Copy Markdown
Contributor

Closes #195

@0xGeorgii 0xGeorgii self-assigned this May 18, 2026
@0xGeorgii 0xGeorgii added the codegen Bytecode emitting label May 18, 2026
@0xGeorgii 0xGeorgii requested a review from Copilot May 18, 2026 07:28
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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::Assert in Compiler::lower_statement via a new lower_assert_statement helper guarded by cov_mark.
  • Add TypeMismatchContext::Assert and extract a validate_bool_expression helper to deduplicate bool checks across if / 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
Copy link
Copy Markdown

codecov Bot commented May 18, 2026

Codecov Report

❌ Patch coverage is 98.38710% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
core/type-checker/src/type_checker.rs 96.55% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@0xGeorgii 0xGeorgii merged commit ffb8d9f into main May 18, 2026
10 checks passed
@0xGeorgii 0xGeorgii deleted the 195-assert-keyword-support-in-spec branch May 18, 2026 08:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

codegen Bytecode emitting

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Assert keyword support in spec

2 participants