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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 10 additions & 2 deletions modules/standard/List.chpl
Expand Up @@ -518,8 +518,16 @@ module List {
@chpldoc.nodoc
proc ref _commonInitFromIterable(iterable) lifetime this < iterable {
this._firstTimeInitializeArrays();
for x in iterable do
pushBack(x);
if isSubtype(this.eltType, list) {
for x in iterable {
var subList: this.eltType = x;
pushBack(subList);
}
} else {
for x in iterable {
pushBack(x);
}
}
}

@chpldoc.nodoc
Expand Down
@@ -0,0 +1,9 @@
use List;

// this works, creates a list of arrays
var a: list(?) = [[1,2,3],[4,5,6]];
compilerWarning(a.type:string);

// this segfaults at runtime, no matter the domain used for the array
var b: list([1..3] int) = [[1,2,3],[4,5,6]];
compilerWarning(b.type:string);
@@ -0,0 +1 @@
bug: init= segfaults at runtime
jabraham17 marked this conversation as resolved.
Show resolved Hide resolved
@@ -0,0 +1,2 @@
listInitEqualsArrayBug.chpl:5: warning: list([domain(1,int(64),one)] int(64),false)
listInitEqualsArrayBug.chpl:9: warning: list([domain(1,int(64),one)] int(64),false)
@@ -0,0 +1,20 @@
use List;

var lst1: list(list(string)) = [["1", "2", "3"], ["a","b","c"]];
writeln(lst1.type: string);
writeln(lst1);

var lst2: list(list(list(string))) = [
[["1", "2", "3"], ["a","b","c"]],
[["4", "5", "6"], ["d","e","f"]]
];
writeln(lst2.type: string);
writeln(lst2);

var lst3 = new list([1, 3, 5]);
writeln(lst3.type: string);
writeln(lst3);

var lst4 = new list([[1,2,3], [4,5,6]]);
writeln(lst4.type: string);
writeln(lst4);
@@ -0,0 +1,8 @@
list(list(string,false),false)
[[1, 2, 3], [a, b, c]]
list(list(list(string,false),false),false)
[[[1, 2, 3], [a, b, c]], [[4, 5, 6], [d, e, f]]]
list(int(64),false)
[1, 3, 5]
list([domain(1,int(64),one)] int(64),false)
[1 2 3, 4 5 6]