New Issue: method-on-nilable convenience feature: what should be the type of 'this'

20651, "vasslitvinov", "method-on-nilable convenience feature: what should be the type of 'this'", "2022-09-07T18:11:54Z"

Spinning this off of language specification updates for parenless methods by mppf · Pull Request #20619 · chapel-lang/chapel · GitHub

If we have a param- or type-returning method on a class, what should be the type of this in the body of the method, if not specified explicitly?

  • (A) generic over any memory management and nilability, therefore matching those of the actual argument, or
  • (B) non-nilable borrowed variant of the class?

The broader agenda of this issue is to omit nilability checking in any function that will not be executed at run time. Such functions are all param- and type-returning functions except functions returning runtime types. For example:

proc myRank(c: MyClass?) param {
  return c.myArrayField.rank;
}

Even if the actual argument to myRank() at run time is nil, the function will not be executed at run time, so the nilability of c in c.myArrayField does not matter.

The current approach of performing nilability checking within such functions has the advantage of consistency with compiler behavior within functions that DO execute at run time. W.r.t. the this formal, the behavior specified in the spec as of #20619 is consistent with the behavior of this in type methods on classes.