chapel icon indicating copy to clipboard operation
chapel copied to clipboard

[Bug]: `const ref` attached to vararg formal arguments allows their modification

Open lydia-duncan opened this issue 5 months ago • 0 comments

Summary of Problem

Description: This is the remaining issue tracked by #25858 which I wasn't able to solve yet.

The individual arguments passed to a const ref varargs should behave the same as though they were passed to a const ref tuple or individually - they should trigger an error about modifying a const if the body of the function tries to modify them. However, today a program that does so compiles without issue and allows modification to occur.

This was easily solved for const and const in, but const ref for some reason is proving more elusive.

Is this issue currently blocking your progress? No, just tracking it

Steps to Reproduce

Source Code:

proc myPrintln(const ref args...)
{
  writeln("args.type     = ", args.type:string);
  writeln("args (before) = ", args);

  args[0] *= 10;  // should not be allowed

  writeln("args (after) = ", args);
}

myPrintln(1, 2.3, "four");

Compile command: chpl foo.chpl

Execution command: N/A - should fail at compilation, but does not

Associated Future Test(s): test/functions/varargs/constRefVarargs.chpl #25902

Configuration Information

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

lydia-duncan avatar Sep 06 '24 21:09 lydia-duncan