chapel
chapel copied to clipboard
Unhelpful error message when iterating over a nilable
Consider the following erroneous code:
class MyClass {
iter these() {
for item in 1..10 do yield item;
}
}
var c: owned MyClass?;
c = new MyClass();
for item in c do // Needs c!
writeln(item);
The loop on the last couple of lines must use c!
instead of c
. While the compiler is typically able to recommend postfix-!
as appropriate, it fails to do so here:
$CHPL_HOME/theseNilable.chpl:11: error: cannot iterate over values of type owned MyClass?