[Chapel Merge] Make first-class functions retain return intents

Branch: refs/heads/main
Revision: 8849205
Author: bradcray
Link: Make first-class functions retain return intents by bradcray · Pull Request #18907 · chapel-lang/chapel · GitHub
Log Message:

Merge pull request #18907 from bradcray/fcfs-retain-return-intents

Make first-class functions retain return intents

[reviewed by @vasslitvinov]

Prior to this commit, the compiler's implementation of first-class
functions as class methods failed to preserve the function's return
intent on the method—using the default RET_VALUE return intent
instead. As pointed out by @thomasrolinger on issue #18905,
this made 'ref' and 'const ref' return intents fail to work as expected/
intended.

Here, I'm propagating the return intent of the function being
captured into the classes and methods used to implement the
first-class function which makes the const ref and ref cases
work as expected. I added a pair of tests to lock this behavior
in as well.

I tried adding tests to see whether a param return intent would
work correctly, but had challenges unrelated to the return intent
itself (e.g., FCFs don't seem to do very well with param arguments
or computations), so left that as future work, under the general
"FCFs haven't really received much attention yet" mantle and the
sense that I was not making things worse in this regard.

I've added a future here indicating that we don't properly complain
about functions that return 'const ref' being stored in 'ref'
variables, which is orthogonal to this issue but something I
stumbled across in testing and filed #18909 to capture.

Resolves #18905

Modified Files:
A test/functions/firstClassFns/constRefRetIntent.chpl

A test/functions/firstClassFns/constRefRetIntent.good
A test/functions/firstClassFns/refRetIntent.chpl
A test/functions/firstClassFns/refRetIntent.good
A test/functions/retIntent/retConstRefToRef.bad
A test/functions/retIntent/retConstRefToRef.chpl
A test/functions/retIntent/retConstRefToRef.future
A test/functions/retIntent/retConstRefToRef.good
M compiler/resolution/preFold.cpp

Compare: https://github.com/chapel-lang/chapel/compare/06747a19ebae...8849205469bb