ref: 545ac708bc6fbae20d8ce00ad93378cb8bb0d28f
parent: 3423dd0094c98305133e3dc142761de12461ae22
author: Ori Bernstein <[email protected]>
date: Tue Jun 5 16:01:53 EDT 2012
Make function type inference less buggy. If infercall() was called on an expression where the callee had not already been inferred to be a function, we would die. Don't do that.
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -221,6 +221,11 @@
inferexpr(n->expr.args[0], NULL, NULL);
ft = type(n->expr.args[0]);
+ if (ft->type == Tyvar) {
+ /* the first arg is the function itself, so it shouldn't be counted */
+ ft = mktyfunc(n->line, &n->expr.args[1], n->expr.nargs - 1, mktyvar(n->line));
+ unify(n, type(n->expr.args[0]), ft);
+ }
for (i = 1; i < n->expr.nargs; i++) {
inferexpr(n->expr.args[i], NULL, NULL);
unify(n, ft->sub[i], type(n->expr.args[i]));