Skip to content

Require explicit struct types in literals and destructuring - #193

Merged
someone235 merged 3 commits into
kaspanet:masterfrom
someone235:typed-struct-lit
Aug 3, 2026
Merged

Require explicit struct types in literals and destructuring#193
someone235 merged 3 commits into
kaspanet:masterfrom
someone235:typed-struct-lit

Conversation

@someone235

Copy link
Copy Markdown
Contributor

Fixes #157

Struct literals and destructuring patterns now carry an explicit struct name. Struct values are checked nominally instead of being inferred from matching field layouts, making same-shaped
structs unambiguous across assignments, state readers, template validation, and struct arrays.

Language Behavior Changes

  • Struct literals must include their declared type:
Receipt receipt = Receipt {
    orderId: orderId,
    buyer: buyer,
    amount: amount
};

Anonymous literals such as { orderId: orderId, ... } are no longer supported.

  • Struct destructuring must include the expected type:
State {
    count: int previousCount,
    owner: pubkey previousOwner
} = readInputState(1);
  • Typed destructuring disambiguates structs with identical layouts:
AState {
    value: int previousValue
} = readInputStateWithTemplate(
    1,
    prefixLength,
    suffixLength,
    templateHash
);
  • Template-output builtins accept inline typed struct literals:
validateOutputStateWithTemplate(
    0,
    Receipt {
        orderId: orderId,
        buyer: buyer,
        amount: amount
    },
    templatePrefix,
    templateSuffix,
    templateHash
);
  • Struct assignments, arguments, and array elements must use the expected nominal struct type. A different struct with the same fields is no longer accepted based solely on its layout.

@someone235
someone235 merged commit 32c56bd into kaspanet:master Aug 3, 2026
4 checks passed
@someone235
someone235 deleted the typed-struct-lit branch August 3, 2026 06:02
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.

Use rust-style struct literals/destructuring

1 participant