shithub: mc

Download patch

ref: 4b51d0d03ae39f5a48f45d0d408a42917f6f099f
parent: 6d2f54a54d3f8e58f1063374ef82d07f665f5562
author: Ori Bernstein <[email protected]>
date: Sat Jul 21 21:32:05 EDT 2012

Add tests for arity fixes.

--- a/parse/infer.c
+++ b/parse/infer.c
@@ -419,13 +419,18 @@
     }
     for (i = 1; i < n->expr.nargs; i++) {
         if (i == ft->nsub)
-            fatal(n->line, "Calling %s with too many arguments (expected %zd, got %zd)",
-                  ctxstr(st, n->expr.args[0]), ft->nsub, n->expr.nargs);
-        if (ft->sub[i]->type == Tyvalist)
+            fatal(n->line, "%s arity mismatch (expected %zd args, got %zd)",
+                  ctxstr(st, n->expr.args[0]), ft->nsub - 1, n->expr.nargs - 1);
+        if (ft->sub[i]->type == Tyvalist) {
+            i++; /* to prevent triggering the arity mismatch on exit */
             break;
+        }
         inferexpr(st, n->expr.args[i], NULL, NULL);
         unify(st, n->expr.args[0], ft->sub[i], type(st, n->expr.args[i]));
     }
+    if (i < ft->nsub)
+        fatal(n->line, "%s arity mismatch (expected %zd args, got %zd)",
+              ctxstr(st, n->expr.args[0]), ft->nsub - 1, n->expr.nargs - 1);
     settype(st, n, ft->sub[0]);
 }
 
--- /dev/null
+++ b/test/arityhigh.myr
@@ -1,0 +1,7 @@
+const f = {a:int
+
+}
+
+const main = {
+	-> f(1, 2, 3)
+}
--- /dev/null
+++ b/test/aritylow.myr
@@ -1,0 +1,7 @@
+const f = {a:int, b:int, c:int
+
+}
+
+const main = {
+	-> f(1, 2)
+}
--- a/test/tests
+++ b/test/tests
@@ -63,3 +63,5 @@
 F union-missingarg
 F match-badtypes
 F generic-in-const
+F aritylow
+F arityhigh