chapel icon indicating copy to clipboard operation
chapel copied to clipboard

Unhelpful error message when iterating over a nilable

Open e-kayrakli opened this issue 9 months ago • 0 comments

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?

e-kayrakli avatar Apr 26 '24 20:04 e-kayrakli