External Issue: [Bug]: Error passing const actual to ref formal parameter with 'c_ptr'

24797, "Guillaume-Helbecque", "[Bug]: Error passing const actual to ref formal parameter with 'c_ptr'", "2024-04-09T08:52:40Z"

Summary of Problem

Hello, while updating some 1.33.0 code to 2.0.0, I faced something curious. Here is the reproducer:

use CTypes;

record R {
  var arr: c_array(c_int, 10);
}

proc foo(const a: c_ptr(c_int)) {
  writeln("say hello");
}

proc main() {
  const r = new R();

  foo(r.arr);
}

This piece of code compiles and runs for 1.33.0, but fails to compile using 2.0.0 with the following error (which, by the way, seems incomplete):

sandbox.chpl:11: In function 'main':
sandbox.chpl:14: error: const actual is passed to a 'ref' formal of :

Using foo(const a: c_array(c_int)) instead of foo(const a: c_ptr(c_int)) makes things work (for both versions), but this looks strange to me because c_array can coerce with c_ptr. In addition, the reason why I use c_ptr(c_int) instead of c_array(c_int) is that my real code is a bit more complicated: the foo procedure is declared in an external C library, and when I import it using extern proc foo(const a: c_array(c_int));, I get the following error (which I don't get using c_ptr(c_int)):

sandbox.chpl:4: error: a concrete intent is required for the extern function formal 'a' which has record type 'c_array(int(32),10)'

Is this a blocking issue with no known work-arounds?
No, some work-arounds exist.

Steps to Reproduce

Compile command:
chpl foo.chpl

Execution command:
N/A (compile-time error)

Associated Future Test(s):
N/A

Configuration Information

  • Output of chpl --version: 2.0.0
  • Output of $CHPL_HOME/util/printchplenv --anonymize:
  • Back-end compiler and version, e.g. gcc --version or clang --version:
  • (For Cray systems only) Output of module list: