chapelu
September 3, 2024, 6:30pm
1
25858, "ty1027", "[Bug]: 'const' attached to vararg formal arguments allows their modification", "2024-09-03T18:28:40Z"
opened 06:28PM - 03 Sep 24 UTC
closed 02:34PM - 04 Sep 24 UTC
type: Bug
user issue
### Summary of Problem
**Description:**
The following code receives multip… le arguments as a tuple (`args`) and attempts to modify
the 1st element of the tuple. ([ATO](https://ato.pxeger.com/run?1=ZZBNDoIwEIXjxkVPMWFFCZYfN0bCHdwbF4gtkgBtyhBDjCdxw0YP5Wks_hFwVpN537zJvOs9PSaKF113a1AsVo_Z3PNAaZlC2W50XmFR2YnOasYYBSPZTkDJRE9lVSOMqZCSMwE46Ry5QayXiq3i0FcMlgu_0bpG45TRaLoA9p4LqTkdFgxkqL7b-jtwYgj8CPqTpTzkogVsVMHJv1EikOuxz4WQ4YfAhZAtXbCEbLRFo3ccn1S-6TwB))
```chapel
// proc myPrintln(args...) // (*1)
proc myPrintln(const args...) // (*2)
{
writeln("args.type = ", args.type:string);
writeln("args (before) = ", args);
args[0] *= 10; // modify tuple (just for test)
writeln("args (after) = ", args);
}
myPrintln(1, 2.3, "four");
```
With no `const` attached (as in Line (*1)), the code prints
```
args (after) = (10, 2.3, four)
```
as expected. On the other hand, if I attach `const` to `args` (as in Line (*2)),
the code still prints the same result, so allowing the modification of `args`.
I posted the above code in the Chapel Discourse (in this [thread](https://chapel.discourse.group/t/const-attached-to-vararg-formal-argument/36578)), and Brad suggests that it may be a compiler bug
(based on another example code for tuples). Please take a look at the above
Discourse page for Brad's test code and explanations.
**Is this issue currently blocking your progress?**
No. (I happened to observe this behavior when playing with `vararg` for practice).
### Steps to Reproduce
I tested the code with the above ATO site.
Summary of Problem
Description:
The following code receives multiple arguments as a tuple (args) and attempts to modify
the 1st element of the tuple. (ATO )
// proc myPrintln(args...) // (*1)
proc myPrintln(const args...) // (*2)
{
writeln("args.type = ", args.type:string);
writeln("args (before) = ", args);
args[0] *= 10; // modify tuple (just for test)
writeln("args (after) = ", args);
}
myPrintln(1, 2.3, "four");
With no const attached (as in Line (*1)), the code prints
args (after) = (10, 2.3, four)
as expected. On the other hand, if I attach const to args (as in Line (*2)),
the code still prints the same result, so allowing the modification of args.
I posted the above code in the Chapel Discourse (in this thread ), and Brad suggests that it may be a compiler bug
(based on another example code for tuples). Please take a look at the above
Discourse page for Brad's test code and explanations.
Is this issue currently blocking your progress?
No. (I happened to observe this behavior when playing with vararg for practice).
Steps to Reproduce
I tested the code with the above ATO site.