Skip to content

Add typed array literals and numeric hex literals - #194

Merged
someone235 merged 3 commits into
kaspanet:masterfrom
someone235:typed-array-lits
Aug 3, 2026
Merged

Add typed array literals and numeric hex literals#194
someone235 merged 3 commits into
kaspanet:masterfrom
someone235:typed-array-lits

Conversation

@someone235

Copy link
Copy Markdown
Contributor

Closes #159

Introduce explicit types for array literals and redefine hexadecimal literals as numerals. Byte sequences now require explicit casts, while pubkey, sig, and datasig accept correctly
sized hex literals directly.

Language Behavior Changes

  • Array literals now use T{...} instead of untyped [...] syntax.
int[] dynamic = int[]{1, 2, 3};
int[3] inferred = int[_]{1, 2, 3};
int[3] fixed = int[3]{1, 2, 3};

T[]{...} produces a dynamic array, T[_]{...} infers a fixed size, and T[N]{...} requires exactly N elements.

  • Nested array literals retain their element dimensions.
byte[2][_] values = byte[2][_]{byte[2](0x0102), byte[2](0x0304)};

Nested elements must have compatible types and equal fixed dimensions.

  • Hex literals up to eight bytes are now numeric literals.
int mask = 0xff00;
byte tag = 0xff;

They no longer implicitly produce byte arrays. Raw bytes require an immediate byte-array cast:

byte[] data = byte[](0x01020304);
byte[_] fixedData = byte[_](0x010203040506070809);

Hex literals longer than eight bytes remain invalid unless immediately cast to a byte array or fixed byte-sequence type.

  • Fixed byte-sequence types accept direct hex casts with exact size validation.
pubkey key = pubkey(0x0202020202020202020202020202020202020202020202020202020202020202);
sig signature = sig(0x...);         // exactly 65 bytes
datasig dataSignature = datasig(0x...); // exactly 64 bytes
  • Casts between fixed arrays with known, unequal sizes are rejected consistently for every element type.

@someone235
someone235 merged commit 6023e30 into kaspanet:master Aug 3, 2026
4 checks passed
@someone235
someone235 deleted the typed-array-lits branch August 3, 2026 11:09
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.

Allow hex literals for all numeral types

1 participant