Skip to content

Infer int[N] and bool[N] literal types in debug_value_types#167

Open
oskrcl wants to merge 3 commits into
kaspanet:masterfrom
oskrcl:fix/int-n-bool-literal-inference
Open

Infer int[N] and bool[N] literal types in debug_value_types#167
oskrcl wants to merge 3 commits into
kaspanet:masterfrom
oskrcl:fix/int-n-bool-literal-inference

Conversation

@oskrcl

@oskrcl oskrcl commented Jul 22, 2026

Copy link
Copy Markdown

Summary

infer_debug_expr_value_type only recognizes byte[N] array literals.
int[N] and bool[N] literals fall through to the catch-all "byte[]"
type, which causes validateOutputState to reject state fields written
with array literals. A field passed by reference ({ winners: winners })
compiles fine because the declared type from the types map bypasses
literal inference; a field passed by literal ({ winners: [1,2,3,4] })
fails until this fix lands.

Changes

  • silverscript-lang/src/compiler/debug_value_types.rs — in the
    ExprKind::Array arm of infer_debug_expr_value_type, infer int[N]
    for all-Int literals and bool[N] for all-Bool literals, alongside
    the existing byte[N] case. Empty literals now infer "byte[]"
    explicitly (previously "byte[0]" via vacuous .all() on an empty
    iterator).
  • silverscript-lang/tests/compiler_tests.rs — new test
    compiles_validate_output_state_with_int_array_literal exercises
    validateOutputState(0, { x: x + 1, winners: [1,2,3,4] }).
  • silverscript-lang/tests/examples/b3c_array_spike.sil — showcase
    fixture mirroring the inline test.
  • silverscript-lang/src/compiler/debug_value_types.rs #[cfg(test)]
    unit test infers_fixed_array_literal_value_types pins all three new
    inference branches (int[N], bool[N], empty).

Test Evidence

  • cargo test -p silverscript-lang — 305 passed, 0 failed.
  • New regression test fails without the patch: [1,2,3,4] infers as
    "byte[]", compile_encoded_state_object rejects unsized field type
    with validateOutputState does not support field type byte[].
  • b3c_array_spike.sil (literal) compiles only after the patch.
  • Field-reference path is unaffected (declarations already supply the
    declared type); verified empirically.

Notes

  • bool[N] ctor-binding from Rust (Expr::From<Vec<bool>>) is a
    separate bug filed in the upstream issue tracker; not addressed here.
  • No grammar or tree-sitter changes; no state {} declarations block
    patched.

oskrcl added 3 commits July 22, 2026 13:30
The literal-inference path for ExprKind::Array only matched ExprKind::Byte,
causing int[N] and bool[N] literals to fall through to the catch-all
"byte[]" type. This breaks validateOutputState state-region size
computation for non-byte array literals.

- Add ExprKind::Int inference branch (returns "int[N]")
- Add ExprKind::Bool inference branch (returns "bool[N]")
- Handle empty arrays explicitly (return "byte[]" for legacy compat)

Also adds a #[cfg(test)] unit test pinning all three new behaviors.
Regression fixture for the literal-inference bug fixed in the previous
commit. Demonstrates int[4] literal [1,2,3,4] in validateOutputState.

Note: b3c_field_ref_spike.sil and b3c_bool_* removed from this branch --
field-ref path is pre-existing (not the fixed code path); bool[N]
ctor-binding is a separate bug filed in the issue tracker.
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