From da9fe1e040b04cbe816c67fab7cb45d7db75107c Mon Sep 17 00:00:00 2001 From: Kimplul Date: Fri, 26 Apr 2024 16:29:55 +0300 Subject: restructure debugging a bit --- src/check.c | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) (limited to 'src/check.c') 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 +#include #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; -- cgit v1.2.3