Skip to content

Added support for asserts on deserialized data#1346

Draft
batconjurer wants to merge 1 commit into
bat/macros-fixed-lengthfrom
bat/add-macro-postconditions
Draft

Added support for asserts on deserialized data#1346
batconjurer wants to merge 1 commit into
bat/macros-fixed-lengthfrom
bat/add-macro-postconditions

Conversation

@batconjurer

Copy link
Copy Markdown
Contributor

Why this should be merged

Closes #1334

Adds assert post-conditions to the #[unpack(...)] macro. Three forms are supported:

  • Type-level (assert = "|var| { expr }" on the struct annotation): emits require(expr) just before the function returns, with var substituted by result.
  • Field-level (assert = "|var| { expr }" on a field): emits require(expr) immediately after the field is assigned to result, with var substituted by the field's local variable.
  • Element-level (assert = "|each var| { expr }" on a field): for array fields, emits require(expr) inside the decode loop per element; for bytes/string/bytesN fields, emits a post-decode byte iteration loop.

Multiple assert keys may appear on a single annotation. The closure value is a quoted string so commas and = signs inside the expression are not misinterpreted as argument separators. each is rejected at the type level and on non-container fields with a descriptive error.

The multi-line comment parser was also fixed: reforge::get_comment concatenates comment lines without newlines, so strip_comment_prefixes now splits on embedded // occurrences (outside quoted strings) in addition to \n.

How this works

How this was tested

How is this documented

@batconjurer batconjurer requested a review from a team as a code owner May 28, 2026 10:52
@batconjurer batconjurer marked this pull request as draft May 28, 2026 10:52
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.

3 participants