diff options
author | Kimplul <kimi.h.kuparinen@gmail.com> | 2024-04-26 15:29:46 +0300 |
---|---|---|
committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2024-04-26 15:29:46 +0300 |
commit | 9ec0e372e1720b8f0857ee6c99997f695ef9ea5d (patch) | |
tree | be354afd4d845af4e2a8f7f5ac97aefb8bd6d997 /src | |
parent | 7d9e25efd6a6bd95e503adbc3b4e66788ccdebd0 (diff) | |
download | posthaste-9ec0e372e1720b8f0857ee6c99997f695ef9ea5d.tar.gz posthaste-9ec0e372e1720b8f0857ee6c99997f695ef9ea5d.zip |
add auto
Diffstat (limited to 'src')
-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)); |