Skip to content

compiler: add bool[N] ctor binding via Expr::bool_array and From<Vec<bool>> - #170

Open
oskrcl wants to merge 4 commits into
kaspanet:masterfrom
oskrcl:fix/bool-array-ctor-binding
Open

compiler: add bool[N] ctor binding via Expr::bool_array and From<Vec<bool>>#170
oskrcl wants to merge 4 commits into
kaspanet:masterfrom
oskrcl:fix/bool-array-ctor-binding

Conversation

@oskrcl

@oskrcl oskrcl commented Jul 24, 2026

Copy link
Copy Markdown

Summary

Adds helper and trait impl, enabling construction of array values in (VOS) bodies.

Motivation

Covenant contracts using need to construct fields for next-state encoding. Without these helpers, there is no idiomatic way to build expressions programmatically (e.g., from test harnesses or VOS body generation).

Changes

  • **** (+39 lines):

    • — constructs of items, mirroring existing helper
    • — delegates to , placed after
  • **** (+16 lines):

    • — unit test: verifies AST structure
    • — compile test: verifies trait
    • — integration test: field in VOS compiles
    • — integration test: ctor arg via

Verification

  • cargo build --release -p silverscript-lang
  • cargo test -p silverscript-lang --release — 499 passed, 0 failed ✅
  • Branch based on 2a3961c (upstream master HEAD at time of branch)

API Consistency

Follows existing patterns exactly:

  • bool_array mirrors bytes() constructor
  • From<Vec<bool>> mirrors From<Vec<u8>>
  • From<Vec<i64>> (int arrays) unaffected — different trait parameter, zero ambiguity

Depends on: nothing (standalone). Pairs with #PR3 (bool[N] VOS encoding preservation) for full VOS round-trip.

oskrcl added 4 commits July 22, 2026 14:24
…bool>>

The Expr API has helpers for int, bool, byte, bytes, string, but no bool_array
helper nor From<Vec<bool>> impl. This blocks Rust test code from constructing
bool[N] ctor params for silverscript contracts.

- Add Expr::bool_array(Vec<bool>) parallel to Expr::bytes(Vec<u8>)
- Add From<Vec<bool>> for Expr
- Unit tests pin both
Integration test uses bool[2] param initW and field ref initW in
validateOutputState. Uses field ref (not literal) to stay independent
from PR kaspanet#1's literal inference fix.
fixed_type_size in compile.rs handles arrays for byte[] and int[]
but not bool[], causing fixed_state_payload_len to return None for
bool[N] fields. This propagates to compile_encoded_state_object and
compile_encoded_flat_state_fields, rejecting bool[N] in
validateOutputState/validateNextState.

Fix by adding is_bool() branch: bool is 1 byte per element, same
layout as byte[N].

Adds:
- Unit test fixed_type_size_accepts_bool_array in compile.rs
- Integration test compiles_validate_output_state_with_bool_array_field
  in compiler_tests.rs
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.

1 participant