New Issue: Nilability ergonomics features

16931, “vasslitvinov”, “Nilability ergonomics features”, “2021-01-11T23:48:50Z”

This issue discusses which features we would like to add to Chapel to improve usability of non-nilable class types. Individual features should be discussed in their own issues.

  • If-non-nilable #13639 will make a value treated as non-nilable within a conditional that tests whether it is not nil, for example in the following code:
        var current: borrowed MyClass? = ...;
        if current != nil then
          fnExpectingNotNil(current!);  // should not need postfix-!

        proc fnExpectingNotNil(arg: borrowed MyClass) { ..... }
  • Nilable-chaining will provide a shorthand for invoking a method if a value is not nil, as in this code:
        var y = if x != nil then x!.method() else nil;
  • Default-value will provide a shorthand for providing a default value if an expression is nil, as in this code:
        var y = if current != nil then current! else defaultValue;