aboutsummaryrefslogtreecommitdiff
path: root/compile.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-10-09 13:26:28 -0400
committerBruce Hill <bruce@bruce-hill.com>2024-10-09 13:26:28 -0400
commit074cf22ad462eafe963e4a749b2b74cab51211a1 (patch)
treee1d7f938f2d949cc5dcf67ca648f200663e36562 /compile.c
parent47fca946065508cff4151a32b3008c161983fd9d (diff)
Change function syntax from `func(args)->ret` to `func(args -> ret)`
Diffstat (limited to 'compile.c')
-rw-r--r--compile.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/compile.c b/compile.c
index ab596e82..117a65ad 100644
--- a/compile.c
+++ b/compile.c
@@ -2519,6 +2519,16 @@ CORD compile(env_t *env, ast_t *ast)
type_t *ret_t = get_type(body_scope, lambda->body);
if (ret_t->tag == ReturnType)
ret_t = Match(ret_t, ReturnType)->ret;
+
+ if (lambda->ret_type) {
+ type_t *declared = parse_type_ast(env, lambda->ret_type);
+ if (can_promote(ret_t, declared))
+ ret_t = declared;
+ else
+ code_err(ast, "This function was declared to return a value of type %T, but actually returns a value of type %T",
+ declared, ret_t);
+ }
+
fn_ctx.return_type = ret_t;
if (env->fn_ctx->closed_vars) {