Skip to content

Commit b87f731

Browse files
committed
add future for integral return types
Signed-off-by: Ahmad Rezaii <[email protected]>
1 parent 5604d99 commit b87f731

8 files changed

+4220
-1767
lines changed

frontend/test/resolution/testIntegralReturnType.cpp

+1,033-1,033
Large diffs are not rendered by default.
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
integralTests.chpl
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
integralTests.chpl

test/statements/conditionals/integralReturnTypesInConditional.bad

+1,536
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,2 @@
1-
proc testGeneric(arg: bool, type t, type tt) {
2-
var i: t = 0;
3-
var u: tt = 0;
4-
if arg then return i;
5-
else return u;
6-
}
7-
8-
proc testGenericCast(arg: bool, type t, type tt) {
9-
var zero: uint(8);
10-
if arg then return zero:t;
11-
else return zero:tt;
12-
}
13-
14-
proc testParamGenericCast(arg: bool, type t, type tt) {
15-
if arg then return 0:t;
16-
else return 0:tt;
17-
}
18-
19-
proc testExpression(arg: bool, type t, type tt) {
20-
var zero: uint(8);
21-
var x = if arg then zero:t else zero:tt;
22-
writeln("testExpression: when ", arg:string, " ", t:string, " ",
23-
tt:string, " then ", x.type:string);
24-
}
25-
26-
proc testParamExpression(arg: bool, type t, type tt) {
27-
var x = if arg then 0:t else 0:tt;
28-
writeln("testParamExpression: when ", arg:string, " ", t:string, " ",
29-
tt:string, " then ", x.type:string);
30-
}
31-
32-
const A = [true, false];
33-
34-
const Ti = (0:int(8), 0:int(16), 0:int(32), 0:int(64));
35-
const Tu = (0:uint(8), 0:uint(16), 0:uint(32), 0:uint(64));
36-
37-
for a in A {
38-
for ti in Ti {
39-
for tti in Ti {
40-
var xxx = testGeneric(a, ti.type, tti.type);
41-
writeln("testGeneric: when ", a:string, " ", ti.type:string, " ",
42-
tti.type:string, " then ", xxx.type:string);
43-
var yyy = testGenericCast(a, ti.type, tti.type);
44-
writeln("testGenericCast: when ", a:string, " ", ti.type:string, " ",
45-
tti.type:string, " then ", yyy.type:string);
46-
testExpression(a, ti.type, tti.type);
47-
testParamExpression(a, ti.type, tti.type);
48-
var zzz = testParamGenericCast(a, ti.type, tti.type);
49-
writeln("testParamGenericCast: when ", a:string, " ", ti.type:string, " ",
50-
tti.type:string, " then ", zzz.type:string);
51-
}
52-
for tu in Tu {
53-
testExpression(a, ti.type, tu.type);
54-
testExpression(a, tu.type, ti.type);
55-
testParamExpression(a, ti.type, tu.type);
56-
testParamExpression(a, tu.type, ti.type);
57-
var x = testGeneric(a, ti.type, tu.type);
58-
writeln("testGeneric: when ", a:string, " ", ti.type:string, " ",
59-
tu.type:string, " then ", x.type:string);
60-
var xx = testGeneric(a, tu.type, ti.type);
61-
writeln("testGeneric: when ", a:string, " ", tu.type:string, " ",
62-
ti.type:string, " then " , xx.type:string);
63-
64-
var y = testGenericCast(a, ti.type, tu.type);
65-
writeln("testGenericCast: when ", a:string, " ", ti.type:string, " ",
66-
tu.type:string, " then " , y.type:string);
67-
var yy = testGenericCast(a, tu.type, ti.type);
68-
writeln("testGenericCast: when ", a:string, " ", tu.type:string, " ",
69-
ti.type:string, " then " , yy.type:string);
70-
71-
var z = testParamGenericCast(a, ti.type, tu.type);
72-
writeln("testParamGenericCast: when ", a:string, " ", ti.type:string, " ",
73-
tu.type:string, " then ", z.type:string);
74-
var zz = testParamGenericCast(a, tu.type, ti.type);
75-
writeln("testParamGenericCast: when ", a:string, " ", tu.type:string, " ",
76-
ti.type:string, " then ", zz.type:string);
77-
}
78-
}
79-
for tz in Tu {
80-
for tzz in Tu {
81-
var xxx = testGeneric(a, tz.type, tzz.type);
82-
writeln("testGeneric: when ", a:string, " ", tz.type:string, " ",
83-
tzz.type:string, " then " , xxx.type:string);
84-
var yyy = testGenericCast(a, tz.type, tzz.type);
85-
writeln("testGenericCast: when ", a:string, " ", tz.type:string, " ",
86-
tzz.type:string, " then " , yyy.type:string);
87-
testExpression(a, tz.type, tzz.type);
88-
testParamExpression(a, tz.type, tzz.type);
89-
var zzz = testParamGenericCast(a, tz.type, tzz.type);
90-
writeln("testParamGenericCast: when ", a:string, " ", tz.type:string, " ",
91-
tzz.type:string, " then ", zzz.type:string);
92-
}
93-
}
94-
}
1+
require "integralTests.chpl";
2+
use integralTests;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
The return type of an expression or statement should not be sensitive to the order
2+
of the branches in a conditional statement.
3+
#26991

test/statements/conditionals/integralReturnTypesInConditional.good

+1,536-640
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
#!/usr/bin/env python3
2+
3+
integral_types = [
4+
"int(8)", "int(16)", "int(32)", "int(64)",
5+
"uint(8)", "uint(16)", "uint(32)", "uint(64)"
6+
]
7+
8+
boolean_strs = ["true", "false"]
9+
10+
output_file = "integralTests.chpl"
11+
12+
with open(output_file, "w") as f:
13+
for bool_str in boolean_strs:
14+
for type1 in integral_types:
15+
for type2 in integral_types:
16+
f.write("{\n")
17+
f.write(f" proc testProcCastZero(arg: bool) {{\n")
18+
f.write(f" if arg then return 0:{type1}; else return 0:{type2};\n")
19+
f.write(" }\n")
20+
f.write(f" var x = testProcCastZero({bool_str});\n")
21+
f.write(f" writeln(\"testProcCastZero: when {bool_str} {type1} {type2} then \", x.type:string);\n")
22+
f.write("}\n\n")
23+
24+
f.write("{\n")
25+
f.write(f" proc testProcZero(arg: bool) {{\n")
26+
f.write(f" var i: {type1} = 0;\n")
27+
f.write(f" var u: {type2} = 0;\n")
28+
f.write(f" if arg then return i; else return u;\n")
29+
f.write(" }\n")
30+
f.write(f" var x = testProcZero({bool_str});\n")
31+
f.write(f" writeln(\"testProcZero: when {bool_str} {type1} {type2} then \", x.type:string);\n")
32+
f.write("}\n\n")
33+
34+
f.write("{\n")
35+
f.write(f" proc testProcCastMax(arg: bool) {{\n")
36+
f.write(f" if arg then return max({type1}):{type1}; else return max({type2}):{type2};\n")
37+
f.write(" }\n")
38+
f.write(f" var x = testProcCastMax({bool_str});\n")
39+
f.write(f" writeln(\"testProcCastMax: when {bool_str} {type1} {type2} then \", x.type:string);\n")
40+
f.write("}\n\n")
41+
42+
f.write("{\n")
43+
f.write(f" proc testProcMax(arg: bool) {{\n")
44+
f.write(f" var i: {type1} = max({type1});\n")
45+
f.write(f" var u: {type2} = max({type2});\n")
46+
f.write(f" if arg then return i; else return u;\n")
47+
f.write(" }\n")
48+
f.write(f" var x = testProcMax({bool_str});\n")
49+
f.write(f" writeln(\"testProcMax: when {bool_str} {type1} {type2} then \", x.type:string);\n")
50+
f.write("}\n\n")
51+
52+
f.write("{\n")
53+
f.write(f" proc testParamProcCastZero(param arg: bool) param {{\n")
54+
f.write(f" if arg then return 0:{type1}; else return 0:{type2};\n")
55+
f.write(" }\n")
56+
f.write(f" param x = testParamProcCastZero({bool_str});\n")
57+
f.write(f" writeln(\"testParamProcCastZero: when {bool_str} {type1} {type2} then \", x.type:string);\n")
58+
f.write("}\n\n")
59+
60+
f.write("{\n")
61+
f.write(f" proc testParamProcZero(param arg: bool) param {{\n")
62+
f.write(f" param i: {type1} = 0;\n")
63+
f.write(f" param u: {type2} = 0;\n")
64+
f.write(f" if arg then return i; else return u;\n")
65+
f.write(" }\n")
66+
f.write(f" param x = testParamProcZero({bool_str});\n")
67+
f.write(f" writeln(\"testParamProcZero: when {bool_str} {type1} {type2} then \", x.type:string);\n")
68+
f.write("}\n\n")
69+
70+
f.write("{\n")
71+
f.write(f" proc testParamProcCastMax(param arg: bool) param {{\n")
72+
f.write(f" if arg then return max({type1}):{type1}; else return max({type2}):{type2};\n")
73+
f.write(" }\n")
74+
f.write(f" param x = testParamProcCastMax({bool_str});\n")
75+
f.write(f" writeln(\"testParamProcCastMax: when {bool_str} {type1} {type2} then \", x.type:string);\n")
76+
f.write("}\n\n")
77+
78+
f.write("{\n")
79+
f.write(f" proc testParamProcMax(param arg: bool) param {{\n")
80+
f.write(f" param i: {type1} = max({type1});\n")
81+
f.write(f" param u: {type2} = max({type2});\n")
82+
f.write(f" if arg then return i; else return u;\n")
83+
f.write(" }\n")
84+
f.write(f" param x = testParamProcMax({bool_str});\n")
85+
f.write(f" writeln(\"testParamProcMax: when {bool_str} {type1} {type2} then \", x.type:string);\n")
86+
f.write("}\n\n")
87+
88+
f.write("{\n")
89+
f.write(f" var b: bool = {bool_str};\n")
90+
f.write(f" var x = if b then 0:{type1} else 0:{type2};\n")
91+
f.write(f" writeln(\"testExpressionZero: when {bool_str} {type1} {type2} then \", x.type:string);\n")
92+
f.write("}\n\n")
93+
94+
f.write("{\n")
95+
f.write(f" var b: bool = {bool_str};\n")
96+
f.write(f" var x = if b then max({type1}):{type1} else max({type2}):{type2};\n")
97+
f.write(f" writeln(\"testExpressionMax: when {bool_str} {type1} {type2} then \", x.type:string);\n")
98+
f.write("}\n\n")
99+
100+
f.write("{\n")
101+
f.write(f" param x = if {bool_str} then 0:{type1} else 0:{type2};\n")
102+
f.write(f" writeln(\"testParamExpressionZero: when {bool_str} {type1} {type2} then \", x.type:string);\n")
103+
f.write("}\n\n")
104+
105+
f.write("{\n")
106+
f.write(f" param x = if {bool_str} then max({type1}):{type1} else max({type2}):{type2};\n")
107+
f.write(f" writeln(\"testParamExpressionMax: when {bool_str} {type1} {type2} then \", x.type:string);\n")
108+
f.write("}\n\n")

0 commit comments

Comments
 (0)