External Issue: first-class functions don’t maintain the 'ref' return intent

18905, "thomasrolinger", "first-class functions don’t maintain the 'ref' return intent", "2022-01-03T21:03:11Z"

Summary of Problem

If a first class function has a ref intent, it does not seem to be maintained, resulting in a compiler error. Brad has looked at this briefly and suggested filing the issue.

Steps to Reproduce

Source Code:

var A: [1..3] int;

proc foo(x: int) ref {
  return A[x];
}

proc bar(fn) {
  ref x    = fn(2);
  x = 42;
}

bar(foo);
writeln(A);

Compile command:
chpl issue.chpl

Compiler error:
issue.chpl:7: In function 'bar': issue.chpl:8: error: Cannot set a non-const reference to a const variable. issue.chpl:12: called as bar(fn: shared chpl__fcf_type_int64_t__ref_int64_t) note: generic instantiations are underlined in the above callstack

Configuration Information

  • Output of chpl --version:chpl version 1.26.0 pre-release (dbe3743)
  • Output of $CHPL_HOME/util/printchplenv --anonymize:
    CHPL_TARGET_PLATFORM: linux64
    CHPL_TARGET_COMPILER: llvm
    CHPL_TARGET_ARCH: x86_64
    CHPL_TARGET_CPU: native *
    CHPL_LOCALE_MODEL: flat
    CHPL_COMM: gasnet *
    CHPL_COMM_SUBSTRATE: ibv *
    CHPL_GASNET_SEGMENT: large
    CHPL_TASKS: qthreads *
    CHPL_LAUNCHER: gasnetrun_ibv *
    CHPL_TIMERS: generic
    CHPL_UNWIND: none
    CHPL_MEM: jemalloc *
    CHPL_ATOMICS: cstdlib
    CHPL_NETWORK_ATOMICS: none
    CHPL_GMP: bundled *
    CHPL_HWLOC: bundled *
    CHPL_RE2: bundled
    CHPL_LLVM: bundled *
    CHPL_AUX_FILESYS: none