Skip to content

An array inside a tuple literal built at run time cannot be changed (push unresolved; const has no storage) #486

Description

@ASDAlexander77

An array inside a tuple literal built at run time cannot be changed through the tuple. There are two shapes.

1. A constant array inside a tuple that has a run-time value: push does not resolve, with let or const.

function main() {
    let x = 3;
    let t = [x, [1]];
    t[1].push(2);
    print(t[1].length);
}
error: Can't resolve property 'push' of type s32[]

The tuple's type is tuple<number, const_array<si32, 1>>: the inner literal keeps its constant-array type instead of being widened to s32[] (createTupleFromArrayLiteral takes each value's type as is).

Expected: 2.

2. A const of a run-time tuple has no storage: an array in it cannot be changed.

function main() {
    let x = 3;
    const nt = [x, [2, [3, 4]]];
    nt[1][1].push(5);
    print(nt[1][1].length);
}
error: Can't get reference of the array, ensure const array is not used

Expected: 3. With let nt it prints 3 (since #484; on main the let form crashes, which was #479).

processConstRef gives a const storage for a constant array, an array, a constant tuple holding an array (#484), a record read from a literal slot that owns memory, and a few other cases. A tuple built by ts.CreateTuple with an array inside is not among them, so nt is folded to the SSA value, and push has no reference to work through.

Both shapes give the same errors on main (77d9a6a) and with #484.

Found while testing #484 (#479).

🤖 Generated with Claude Code

Activity

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions