diff options
-rw-r--r-- | src/check.c | 8 |
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)); |