aboutsummaryrefslogtreecommitdiff
path: root/src/check.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/check.c')
-rw-r--r--src/check.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/check.c b/src/check.c
index 498fcf8..cdac83e 100644
--- a/src/check.c
+++ b/src/check.c
@@ -70,6 +70,10 @@ static int analyze_type(struct scope *scope, struct ast *n)
n->t = TYPE_DATE;
return 0;
}
+ else if (same_id(n->type, "auto")) {
+ n->t = TYPE_AUTO;
+ return 0;
+ }
semantic_error(scope, n, "no such type: %s", n->type);
return -1;
@@ -424,6 +428,10 @@ static int analyze_return(struct state *state, struct scope *scope,
if (analyze(state, scope, expr))
return -1;
+ /* deduce return type from first return we hit */
+ if (parent->t == TYPE_AUTO)
+ parent->t = expr->t;
+
if (expr->t != parent->t) {
semantic_error(scope, r, "return type mismatch: %s vs %s",
type_str(parent->t), type_str(expr->t));