Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent modification of const ref varargs, too #25902

Merged
merged 8 commits into from
Oct 9, 2024
2 changes: 1 addition & 1 deletion compiler/resolution/expandVarArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ static void expandVarArgsBody(FnSymbol* fn,
}

if (formal->intent == INTENT_CONST || formal->intent == INTENT_CONST_IN ||
formal->intent == INTENT_BLANK) {
formal->intent == INTENT_CONST_REF || formal->intent == INTENT_BLANK) {
// TODO: Note that this will be overly strict for arrays, syncs, and
// atomics, since their default is "pass-by-ref". However, we think this is
// okay for now, in part due to thinking it's unlikely to be relied upon and
Expand Down
1 change: 1 addition & 0 deletions compiler/resolution/functionResolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9599,6 +9599,7 @@ static void resolveMoveForRhsCallExpr(CallExpr* call, Type* rhsType) {

static void moveSetConstFlagsAndCheck(CallExpr* call, CallExpr* rhs) {
if (rhs->isPrimitive(PRIM_GET_MEMBER) ||
rhs->isPrimitive(PRIM_GET_MEMBER_VALUE) ||
lydia-duncan marked this conversation as resolved.
Show resolved Hide resolved
rhs->isPrimitive(PRIM_ADDR_OF))
{
if (SymExpr* rhsBase = toSymExpr(rhs->get(1))) {
Expand Down
12 changes: 12 additions & 0 deletions test/functions/varargs/constRefVarargs.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Taken from https://github.com/chapel-lang/chapel/issues/25858
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");
3 changes: 3 additions & 0 deletions test/functions/varargs/constRefVarargs.good
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
constRefVarargs.chpl:2: In function 'myPrintln':
constRefVarargs.chpl:7: error: cannot assign to const variable
constRefVarargs.chpl:12: called as myPrintln(args(0): int(64), args(1): real(64), args(2): string)
12 changes: 12 additions & 0 deletions test/functions/varargs/constRefVarargsQuery.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Taken from https://github.com/chapel-lang/chapel/issues/25858, modified
proc myPrintln(const ref args...?k)
{
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");
3 changes: 3 additions & 0 deletions test/functions/varargs/constRefVarargsQuery.good
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
constRefVarargsQuery.chpl:2: In function 'myPrintln':
constRefVarargsQuery.chpl:7: error: cannot assign to const variable
constRefVarargsQuery.chpl:12: called as myPrintln(args(0): int(64), args(1): real(64), args(2): string)
7 changes: 3 additions & 4 deletions test/functions/varargs/varargsModArray.good
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
varargsModArray.chpl:2: warning: inferring a default intent to be 'ref' is deprecated - please use an explicit 'ref' intent for the argument 'args'
args.type = ([domain(1,int(64),one)] int(64),real(64),string)
args (before) = (1 2 3, 2.3, four)
args (after) = (10 2 3, 2.3, four)
varargsModArray.chpl:2: In function 'myPrintln':
varargsModArray.chpl:7: error: cannot assign to const variable
varargsModArray.chpl:13: called as myPrintln(args(0): [domain(1,int(64),one)] int(64), args(1): real(64), args(2): string)
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use DataFrames;

var validBits = [true, false, true, false, true];

var columnOne: owned Series? = new owned TypedSeries(["a", "b", "c", "d", "e"], validBits);
var columnTwo: owned Series? = new owned TypedSeries([1, 2, 3, 4, 5], validBits);
var columnThree: owned Series? = new owned TypedSeries([10.0, 20.0, 30.0, 40.0, 50.0]);

var dom = {"columnOne", "columnTwo", "columnThree"};
var columns: [dom] owned Series?;
columns["columnOne"] = columnOne;
columns["columnTwo"] = columnTwo;
columns["columnThree"] = columnThree;
var idx = new shared TypedIndex(["rowOne", "rowTwo", "rowThree", "rowFour", "rowFive"]);

var dataFrame = new owned DataFrame(columns, idx);
var noIndex = new owned DataFrame(columns);
writeln(dataFrame);
writeln();
writeln(dataFrame["columnThree"]);
writeln();
writeln(noIndex);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-snoParSafeWarning
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
columnOne columnThree columnTwo
rowOne a 10.0 1
rowTwo None 20.0 None
rowThree c 30.0 3
rowFour None 40.0 None
rowFive e 50.0 5

rowOne 10.0
rowTwo 20.0
rowThree 30.0
rowFour 40.0
rowFive 50.0
dtype: real(64)

columnOne columnThree columnTwo
0 a 10.0 1
1 None 20.0 None
2 c 30.0 3
3 None 40.0 None
4 e 50.0 5
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import pandas as pd

columnOne = ["a", None, "c", None, "e"]
columnTwo = [1, None, 3, None, 5]
columnThree = [10.0, 20.0, 30.0, 40.0, 50.0]

idx = pd.Index(["rowOne", "rowTwo", "rowThree", "rowFour", "rowFive"])
dataFrame = pd.DataFrame({ "columnOne": columnOne,
"columnTwo": columnTwo,
"columnThree": columnThree },
idx)
noIndex = pd.DataFrame({ "columnOne": columnOne,
"columnTwo": columnTwo,
"columnThree": columnThree })


print dataFrame
print
print dataFrame["columnThree"]
print
print noIndex
3 changes: 3 additions & 0 deletions test/library/draft/DataFrames/psahabu/HelloDataFrame.bad
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
HelloDataFrame.chpl:9: error: const actual is passed to a 'ref' formal of init=()
HelloDataFrame.chpl:9: error: const actual is passed to a 'ref' formal of init=()
HelloDataFrame.chpl:9: error: const actual is passed to a 'ref' formal of init=()
2 changes: 2 additions & 0 deletions test/library/draft/DataFrames/psahabu/HelloDataFrame.future
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bug: owned objects are supported with associative array literals
#26035