chapel-lang / chapel

a Productive Parallel Programming Language
https://chapel-lang.org
Other
1.75k stars 410 forks source link

Unhelpful error message when iterating over a nilable #24943

Open e-kayrakli opened 2 weeks ago

e-kayrakli commented 2 weeks ago

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?