[Chapel Merge] Fix issue with variable init from return intent ov

Branch: refs/heads/main
Revision: 4e97e1e
Author: mppf
Log Message:

Merge pull request #18333 from mppf/issue-18205

Fix issue with variable init from return intent overloads

Fixes #18205.

Adjusts resolveInitVar to handle the combination of PRIM_INIT_VAR and a
ContextCallExpr RHS directly. It's necessary to do it here to avoid
adding an init= call for a ref RHS. If the init= call is added, we
will be relying on copy elision to remove the copy, but copy elision runs
in the callDestructors pass after the return intent overloading has been
handled in cullOverReferences. So, handling it immediately here in
resolveInitVar addresses that ordering issue.

Adds a test based on the example in issue #18205.

Reviewed by @dlongnecke-cray - thanks!

  • [x] full local testing

    Modified Files:
    A test/functions/ferguson/ref-pair/issue-18205.chpl
    A test/functions/ferguson/ref-pair/issue-18205.good
    M compiler/resolution/functionResolution.cpp
    M test/statements/manage/ContextManagerSyntax.good
    M test/statements/manage/OverloadedReturnIntent.good

    Compare: https://github.com/chapel-lang/chapel/compare/f84d8dcb053c...4e97e1e8f253