chapel-lang / chapel

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

How should forwarding work on nilable fields? #14560

Open vasslitvinov opened 4 years ago

vasslitvinov commented 4 years ago

When a method is forwarded to a field of a nillable-class type, should the postfix-! be inserted automatically? should such forwarding be unavailable? other semantics?

class CC {
  forwarding var ff: owned DD? = new owned DD();
}

class DD {
  proc fun() {
    writeln("in DD.fun");
  }
}

var inst = new CC();
inst.fun();         // OK to forward to 'inst.ff' ?

Currently, when #14559 is open, the above succeeds in a prototype module and fails in a production module. In a prototype module, the compiler inserts ! implicitly, converting inst.fun() to inst.ff!.fun().

vasslitvinov commented 4 years ago

@mppf what do you suggest we do here?

mppf commented 4 years ago

I think the code would need to be written as e.g.

class CC {
  var ff: owned DD? = new owned DD();
  forwarding ff!;
}

In other words it would not add the ! by default and the user could opt in to it if that is desired. (Or use a non-nilable type).