aboutsummaryrefslogtreecommitdiff
path: root/src/typecheck.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-11-22 19:11:55 -0500
committerBruce Hill <bruce@bruce-hill.com>2025-11-22 21:47:43 -0500
commitbb354d6d3626cdc0c2a1b802a954df244cd1facc (patch)
tree31c5c8c3f21db8706e1fc7f78194500e03d1780e /src/typecheck.c
parent0aeacfbd83b0afe8a8ea654bc1554b8d7d29e9b1 (diff)
Fixes for conditional expressions for optional types
Diffstat (limited to 'src/typecheck.c')
-rw-r--r--src/typecheck.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/typecheck.c b/src/typecheck.c
index 07c3acf9..a0e55a88 100644
--- a/src/typecheck.c
+++ b/src/typecheck.c
@@ -1376,7 +1376,6 @@ type_t *get_type(env_t *env, ast_t *ast) {
case If: {
DeclareMatch(if_, ast, If);
- if (!if_->else_body) return Type(VoidType);
env_t *truthy_scope = env;
env_t *falsey_scope = env;
@@ -1401,6 +1400,8 @@ type_t *get_type(env_t *env, ast_t *ast) {
}
type_t *true_t = get_type(truthy_scope, if_->body);
+ ast_t *else_body = if_->else_body;
+ if (!else_body) else_body = WrapAST(ast, None, .type = true_t);
type_t *false_t = get_type(falsey_scope, if_->else_body);
type_t *t_either = type_or_type(true_t, false_t);
if (!t_either)