Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A new list isn't created for function calls with rest arguments with lists #43338

Open
MaryamZi opened this issue Aug 29, 2024 · 0 comments
Open
Labels
Priority/High Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. Type/Bug

Comments

@MaryamZi
Copy link
Member

Based on the following example, it seems like we are not always creating a new list? IMO, we need to create a new list always (also in-line with the spec) because it can result in unintentional updates like in the example.

E.g.,

import ballerina/io;

int[] arr = [1, 2];

public function main() {
    fn(...getArr());
    io:println(arr); // updated to [1,2,4] on 2201.4.0
}

function getArr() returns int[] => arr;

function fn(int... x) {
    x.push(4);
}

Btw, just to add, the rest argument doesn't have to be just for the rest param, it can provide arguments for other params also.

[int, int...] arr = [1, 2];

public function main() {
    fn(...getArr()); // valid
}

function getArr() returns [int, int...] => arr;

function fn(int a, int... x) {
}

Originally posted by @MaryamZi in #40040 (comment)

@MaryamZi MaryamZi added Type/Bug Priority/High Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. labels Aug 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority/High Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. Type/Bug
Projects
None yet
Development

No branches or pull requests

1 participant