aboutsummaryrefslogtreecommitdiff
path: root/src/check.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/check.c')
-rw-r--r--src/check.c30
1 files changed, 27 insertions, 3 deletions
diff --git a/src/check.c b/src/check.c
index cdac83e..880f71f 100644
--- a/src/check.c
+++ b/src/check.c
@@ -1,4 +1,5 @@
#include <posthaste/check.h>
+#include <posthaste/debug.h>
#define UNUSED(x) (void)x
@@ -100,7 +101,15 @@ static int analyze_func_def(struct state *state, struct scope *scope,
if (analyze_list(&func_state, func_scope, func_vars(f)))
return -1;
- return analyze(&func_state, func_scope, func_body(f));
+ if (analyze(&func_state, func_scope, func_body(f)))
+ return -1;
+
+ if (f->t == TYPE_AUTO) {
+ semantic_error(scope, f, "unable to determine return type");
+ return -1;
+ }
+
+ return 0;
}
static int analyze_proc_def(struct state *state, struct scope *scope,
@@ -133,6 +142,11 @@ static int analyze_proc_def(struct state *state, struct scope *scope,
return -1;
}
+ if (p->t == TYPE_AUTO) {
+ semantic_error(scope, p, "unable to determine return type");
+ return -1;
+ }
+
return 0;
}
@@ -467,7 +481,7 @@ static int analyze_dot(struct state *state, struct scope *scope, struct ast *d)
return -1;
if (base->t != TYPE_DATE) {
- semantic_error(scope, d, "expected %d, got %d",
+ semantic_error(scope, d, "expected %s, got %s",
type_str(TYPE_DATE), type_str(base->t));
return -1;
}
@@ -566,13 +580,18 @@ static int analyze_proc_call(struct state *state, struct scope *scope,
return -1;
}
+ if (exists->t == TYPE_AUTO) {
+ semantic_error(scope, c, "proc call before deduction of auto");
+ return -1;
+ }
+
struct ast *args = proc_call_args(c);
if (analyze_list(state, scope, args))
return -1;
struct ast *formal = proc_formals(exists);
if (ast_list_len(formal) != ast_list_len(args)) {
- semantic_error(scope, c, "expected %s args, got %s",
+ semantic_error(scope, c, "expected %zd args, got %zd",
ast_list_len(formal), ast_list_len(args));
return -1;
}
@@ -605,6 +624,11 @@ static int analyze_func_call(struct state *state, struct scope *scope,
return -1;
}
+ if (exists->t == TYPE_AUTO) {
+ semantic_error(scope, c, "func call before deduction of auto");
+ return -1;
+ }
+
struct ast *args = func_call_args(c);
if (analyze_list(state, scope, args))
return -1;