Possible compiler bug with iterator

The program below,

iter stoi(const in s: [] string): int {
   for scol in s do {
      yield scol:int;
   }
}
var choice = "3,5";
var fruit = ["Apples", "Bananas", "Oranges", "Peaches", "Pineapples", "Figs"];
var scols = choice.split(",");
for i in stoi(scols) do {
   writeln(fruit[i-1]);
}

crashes the compiler with error message

internal error: AST-AST-TIL-01589 chpl version 2.8.0

Internal errors indicate a bug in the Chapel compiler,
and we're sorry for the hassle.  We would appreciate your reporting this bug --
please see https://chapel-lang.org/bugs.html for instructions.

Changing "const in" to "const ref" in the iterator fixes it.

Since the compiler is asking me to, I will file a bug report.

Cheers,

Nelson

Thanks for reporting this and filing the bug, Nelson!

Unrelated to the bug itself, note that you could forgo writing the stoi iterator and use promotion on the cast operator itself to apply it to the array of values, like so: ATO

var choice = "3,5";
var fruit = ["Apples", "Bananas", "Oranges", "Peaches", "Pineapples", "Figs"];
var scols = choice.split(",");
for i in scols:int do {
   writeln(fruit[i-1]);
}

This has the benefit of also giving you built-in parallel and parallel zippered iteration, if desired (e.g., forall i in scols:int …). It does have the downside of requiring the reader to understand that a scalar cast applied to an array argument results in promotion (i.e., that the whole array isn't being turned into an integer), where we've talked about the syntactic subtlety of that in other recent threads.

-Brad

Nice option Brad! Thanks for pointing it out.