New Issue: Should 'ref' arguments be permitted to take default values?

19116, "bradcray", "Should 'ref' arguments be permitted to take default values?", "2022-01-26T01:25:26Z"

Summary of Problem

While working on an Advent of Code problem, I was writing a recursive procedure, and found myself wanting to have a ref argument (because I wanted changes to it to be reflected up and down the callchain) but also wanted it to have a default value (because I didn't want to require the original caller to require it), where my default value was a literal expression. Today, the compiler complains:

error: const actual is passed to 'ref' formal 'argName' of fnName()

I can see why it might say this—we consider the literal expression to be const/param and to not have an l-value. Yet it would also be very convenient to support such patterns, and I'm not immediately seeing a downside to permitting it.

(I know there've been long-term discussions throughout the project about cases similar to this—whether languages have traditionally conflated constants and refs and l-valueness more than they should, and whether we should balk that trend. I think we do in some cases, but not this one).

Steps to Reproduce

Associated Future Test(s):
test/studies/adventOfCode/2021/bradc/futures/day18-defaultRefVar.chpl #19028

Configuration Information

  • Output of chpl --version: chpl version 1.26.0 pre-release (b94e1c4598)