Skip to content

AST Field drops attributes — #[indexed] lost on onchain event fields #58

Description

@StreamDemon

Summary

The AST Field type carries no attribute storage, so field-level attributes are dropped during parsing. The concrete consequence is that #[indexed] on onchain enum event fields is lost, which will prevent correct EVM topic validation and event codegen once on-chain events are implemented.

Surfaced by Cubic review on PR #57 (compiler bootstrap), thread: #57 (comment). Deferred from that PR as out of scope for the lexer/parser bootstrap — this is a forward-looking gap, not a regression introduced by #57.

Current state (at 9a6f58d)

  • crates/sploosh-ast/src/lib.rsField { name, ty, visibility } has no attributes field. Field is shared by Struct, Actor fields, and VariantKind::Struct(Vec<Field>).
  • crates/sploosh-parser/src/lib.rsattrs() only consumes @-style attributes (@test, @payable, …) via TokenKind::At. The #[...] attribute form is not attached to any AST node, even though the lexer does emit a Hash token.
  • No corpus fixture under tests/corpus/ exercises onchain enum events or #[indexed].

So #[indexed] is unsupported end-to-end today, not merely dropped on fields.

Spec reference

§11.5 — events allow up to 3 #[indexed] fields per variant on EVM (topics 1–3; topic 0 is the signature hash). More than 3 indexed fields on EVM is a compile error. SVM accepts #[indexed] as a no-op.

Scope / acceptance criteria

This should land together with general #[...] attribute parsing and on-chain event codegen in a later slice, where it can be verified end-to-end:

  • Parse #[...] attributes and attach them to fields (extend the AST Field, or a dedicated event-field node, with attribute storage).
  • Preserve #[indexed] through parsing on onchain enum event-variant fields.
  • Enforce the EVM ≤3-indexed-fields limit (compile error past 3); accept #[indexed] as a no-op on SVM.
  • Corpus fixtures covering indexed/non-indexed event fields and the over-limit error case.

Notes

Not blocking — there is no on-chain event parsing or codegen yet. Track for the on-chain modules slice. Distinct from the open spec-debt in #54.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions