Skip to content

[Types] Vec<u8> annotation rejects Vec::with_capacity and cascades into undefined-binding errors #50

Closed

Description

@a19q3

Problem

Adding an explicit Vec<u8> annotation to a working bounded byte encoder makes Vec::with_capacity(52) fail type checking. This was reproduced while simplifying AgoraSeal's external-verifier context encoding.

The failure should either be resolved through expected-element-type propagation or have a precise documented constructor boundary and actionable diagnostic. It should not cascade into errors for every later use of the binding.

Reproduction

Tested on 2026-10-07 with the local cellc binary reporting 0.31.0, metadata schema 72; compiler checkout HEAD 35bf983. These are local binary results, not a fresh release-build attestation.

Use an isolated copy of AgoraSeal's vote package at 5b6106a. Replace its 36 OutPoint byte pushes with:

let mut context: Vec<u8> = Vec::with_capacity(52)
for i in 8..44 {
    context.push(ckb::cell_data_u8(ballot, i) as u8)
}

Keep the subsequent sixteen height-byte pushes, trusted verifier call, and package manifest unchanged. Repin only the isolated copy after this intentional source change, then compile:

cellc lock
cellc . --target riscv64-elf --target-profile ckb --entry-action cast --primitive-strict 0.16 -o /tmp/typed-context.elf

First diagnostic:

error: type mismatch: expected Named("Vec<u8>"), found Named("Vec")
 --> src/main.cell:53:9

The complete package reports 19 diagnostics, including subsequent undefined variable 'context' errors.

Removing only : Vec<u8> makes the same package compile successfully. Using unannotated Vec::new() also compiles, and produces the same ELF hash as unannotated Vec::with_capacity(52) in this reproduction.

The constructor type-checking branch should be inspected for loss of element-type information: the local ("Vec", "with_capacity") branch returns Type::Named("Vec".to_string()). This is an investigation lead, not a complete root-cause analysis.

Expected behavior and acceptance

  • Define and document whether expected Vec<T> types propagate into Vec::new() and Vec::with_capacity(n) for supported fixed-width local elements.
  • Support the annotated Vec<u8> case above, or provide an explicitly documented alternative with a targeted diagnostic if this combination is intentionally excluded.
  • Preserve rejection of incompatible pushed element types and unsupported element layouts.
  • Avoid the undefined-binding diagnostic cascade after a constructor type mismatch.
  • Keep CLI, recovering diagnostics/LSP, metadata, and the collection support matrix consistent.
  • Add focused constructor/contextual-typing regressions; run the applicable project gates for the eventual fix.

This issue does not request Rust heap allocation semantics. CellScript currently documents fixed stack-backed local Vec capacity (256 / element_width); with_capacity(52) is not a declaration of an exact 52-byte backing buffer. See the collection support matrix.

Related: #23 (generic authoring), #47 (allocation-backed collections, a separate scope).

Activity

  1. a19q3 commented on Oct 17, 2026

    @a19q3
    CollaboratorAuthor

    Completed on the 0.32 development branch in 670953c2.

    Expected Vec<T> types now propagate into Vec::new() and Vec::with_capacity(n) for supported fixed-width local elements. Invalid constructor arguments, incompatible pushed elements and unsupported layouts retain targeted errors; recovering diagnostics and LSP no longer cascade into undefined-binding errors. The existing fixed stack-backed capacity model is unchanged.

    Evidence: three constructor/CLI/LSP regressions, documented collection contract, and annotated AgoraSeal encoding example. All three regressions and the unified local ci gate passed again during the 2026-10-17/18 acceptance run. This closes the constructor typing/diagnostic issue; it does not introduce heap allocation semantics.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions