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

Allow creating a list of lists from an array of arrays #24278

Merged
merged 4 commits into from Jan 29, 2024

Conversation

jabraham17
Copy link
Member

@jabraham17 jabraham17 commented Jan 25, 2024

This PR allows creating a list of lists from an array of arrays. Previosuly, the following resulted in a confusing error to users.

var a: list(list(string)) = [["a", "b"], ["c", "d"]];

To resolve the issue, users needed to write the following to workaround this.

var a: list(list(string)) = [new list(["a", "b"]), new list(["c", "d"])];

This PR extends the existing code that allows implicit list creation from arrays to handled arrays and arrays, so that both of the above code snippets work the same. This is also extendable to arrays of arrays of arrays.

Testing

  • paratest without comm
  • paratest with comm

Resolves #24277

[Reviewed by @lydia-duncan]

Signed-off-by: Jade Abraham <jade.abraham@hpe.com>
Copy link
Member

@lydia-duncan lydia-duncan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! We just want to make sure that list(array(something)) doesn't run into problems as a result of this change.

Signed-off-by: Jade Abraham <jade.abraham@hpe.com>
@jabraham17
Copy link
Member Author

Looks like it does

use List;
var a = new list([[1,2,3],[4,5,6]]);
compilerWarning((a.type:string));
writeln(a);

This code works on both main and this branch

This compiles on both main and this branch, but segfaults at runtime for both main and this branch. Not sure whats going on there...

use List;
var a: list([0..<3] int) = [[1,2,3],[4,5,6]];
compilerWarning((a.type:string));
writeln(a);

I will add both of these as tests before I merge this PR (the latter being a future)

Signed-off-by: Jade Abraham <jade.abraham@hpe.com>
Signed-off-by: Jade Abraham <jade.abraham@hpe.com>
@jabraham17 jabraham17 merged commit ccd8959 into chapel-lang:main Jan 29, 2024
7 checks passed
@jabraham17 jabraham17 deleted the list-from-nested-array branch January 29, 2024 18:41
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.

Feature request: list initialisation
3 participants