Skip to content

Add tuple field access and tuple-shaped split results#120

Merged
someone235 merged 5 commits into
kaspanet:masterfrom
someone235:func-tuples
May 10, 2026
Merged

Add tuple field access and tuple-shaped split results#120
someone235 merged 5 commits into
kaspanet:masterfrom
someone235:func-tuples

Conversation

@someone235

Copy link
Copy Markdown
Contributor

This adds tuple field access for tuple-returning function calls, so callers can read individual return values directly with .0, .1, .2, and so on.

It also updates split(int) to behave like a tuple-returning built-in: its two results are accessed with .0 and .1, or destructured with parenthesized tuple binding syntax. As part of making tuple returns
explicit, parenthesized single return types like : (int) are now treated as one-element tuples, not plain scalar returns.

Language Behavior Changes

  • Tuple-returning function calls can be accessed with numeric tuple fields.
function f() : (int, int, int, int) {
    return (2, 3, 4, 5);
}

entrypoint function main() {
    int x = f().2;
    require(f().3 == 5);
}
  • One-element tuple returns use .0.
function f() : (int) {
    return (7);
}

entrypoint function main() {
    require(f().0 == 7);
}
  • Plain scalar function returns remain distinct from tuple returns.
function scalar() : int {
    return 7;
}

function wrapped() : (int) {
    return (7);
}
  • Tuple-returning functions cannot be used directly as scalar expressions.
function f() : (int) {
    return (7);
}

entrypoint function main() {
    require(f() == 7); // invalid; use f().0
}
  • split(int) now uses tuple-style access.
byte[] left = data.split(4).0;
byte[] right = data.split(4).1;
  • Split destructuring now uses parenthesized tuple binding syntax.
(byte[16] left, byte[16] right) = data.split(16);
  • The old split index form is no longer the canonical syntax.
byte[] left = data.split(4)[0]; // use data.split(4).0

@someone235 someone235 merged commit 51d7856 into kaspanet:master May 10, 2026
4 checks passed
@someone235 someone235 deleted the func-tuples branch May 10, 2026 11:06
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