28213, "jabraham17", "[Bug]: Weird behavior returning tuples of iterators", "2025-12-16T01:07:41Z"
I'm finding weird crashes when returning tuples of iterators.
The first example creates 2 lists and then returns a tuple containing iterators for each list (called as .these()). This segfaults
use List;
proc get() {
var l1: list(int);
l1.pushBack(1);
l1.pushBack(2);
l1.pushBack(3);
var l2: list(string);
l2.pushBack("a");
l2.pushBack("b");
l2.pushBack("c");
l2.pushBack("d");
writeln("l1: ", l1);
writeln("l2: ", l2);
return (l1.these(), l2.these());
}
proc main() {
var (ints, strs) = get(); // segfault
writeln("ints: ", ints);
writeln("strs: ", strs);
}
The second example resulted from me trying to simplify the above to not use lists for a reproducer. Instead, I got a similar example that gets a Chapel halt
record R {
var arr: [1..10] string = "hello";
iter these() {
foreach i in arr.domain {
yield arr[i];
}
}
}
proc get() {
var r1 = new R();
var r2 = new R();
return (r1.these(), r2.these());
}
proc main() {
var (it1, it2) = get(); // halt: attempt to dereference nil
writeln("it1: ", it1);
writeln("it2: ", it2);
}
I would have expected both of these patterns to work, and for the final result to be var (it1, it2) = get() to be two arrays.