aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar zinc <zinc@downsta.ir> 2026-10-14 16:07:12 +0330
committerGravatar zinc <zinc@downsta.ir> 2026-10-14 16:07:12 +0330
commit3e71e980c611ac9f00565564bd1e647194f74321 (patch)
tree1a7c7fbafd94749c2439b17a74493b8598518a21
parentconformance: runtime index errors now end with an 'at <stdin>:N in main' trac... (diff)
closures: allow 24 parameters, like functions (was 19)
-rw-r--r--src/compiler/expr.zc4
-rw-r--r--tests/conformance/3-expressions/closure_24_parameters.zc6
-rw-r--r--tests/langerrors/closure_params_25.zc3
3 files changed, 11 insertions, 2 deletions
diff --git a/src/compiler/expr.zc b/src/compiler/expr.zc
index 3d63e4b..c8cb11a 100644
--- a/src/compiler/expr.zc
+++ b/src/compiler/expr.zc
@@ -647,7 +647,7 @@ word closure_layout(int closure_index, int count) {
// variable in. ctx_push / ctx_pop save and restore the enclosing function's
// compiler state around the body.
int closure() {
- int np = 0; char*[20] pn; word[20] pty; int hop, entry, i, t, envl, ncap, c, result, declared = 0, tags = 0, tag, lt, lfl = tline; word[20] ptags;
+ int np = 0; char*[24] pn; word[24] pty; int hop, entry, i, t, envl, ncap, c, result, declared = 0, tags = 0, tag, lt, lfl = tline; word[24] ptags;
word expected = closure_expected; closure_expected = 0;
reserve_closures(nclo + 1);
if (o3on) serr("closures can't be made inside an o3 region");
@@ -668,8 +668,8 @@ int closure() {
if (expected && expected[0] == TY_FN && !tag && (isptr(pty[np]) || pty[np][0] == TY_DYN || pty[np][0] == TY_FN)) ptags[np] = 1;
pnoffs[np] = toff; pnplaces[np] = tpack(); rs_note(RS_PARAM, toff); pn[np] = name();
np++;
- if (np >= 20) { die("too many parameters"); break; }
if (!accept(s_comma)) break;
+ if (np >= 24) { die("too many parameters"); break; } // 24, like a function
}
}
expect(s_rp);
diff --git a/tests/conformance/3-expressions/closure_24_parameters.zc b/tests/conformance/3-expressions/closure_24_parameters.zc
new file mode 100644
index 0000000..e12d258
--- /dev/null
+++ b/tests/conformance/3-expressions/closure_24_parameters.zc
@@ -0,0 +1,6 @@
+// expect: 300/
+// spec 3.15.1 and 5.2.2: a closure takes up to 24 parameters, like a function
+include rt;
+void pn(int x) { rt.put_n(x); rt.put_c(10); }
+fn main() { let f = fn(int a1,int a2,int a3,int a4,int a5,int a6,int a7,int a8,int a9,int a10,int a11,int a12,int a13,int a14,int a15,int a16,int a17,int a18,int a19,int a20,int a21,int a22,int a23,int a24) { return a1+a2+a3+a4+a5+a6+a7+a8+a9+a10+a11+a12+a13+a14+a15+a16+a17+a18+a19+a20+a21+a22+a23+a24; }; pn(f(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24)); return 0; }
+// zc0: skip
diff --git a/tests/langerrors/closure_params_25.zc b/tests/langerrors/closure_params_25.zc
new file mode 100644
index 0000000..0444007
--- /dev/null
+++ b/tests/langerrors/closure_params_25.zc
@@ -0,0 +1,3 @@
+// expect: too many parameters
+include rt;
+fn main() { let f = fn(int a1,int a2,int a3,int a4,int a5,int a6,int a7,int a8,int a9,int a10,int a11,int a12,int a13,int a14,int a15,int a16,int a17,int a18,int a19,int a20,int a21,int a22,int a23,int a24, int a25) { return 0; }; return 0; }