aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c
index a66a40c..df2f687 100644
--- a/src/main.c
+++ b/src/main.c
@@ -253,6 +253,36 @@ type_inference(Analyzer *a, Node *node, TypeScope *scope) {
253 } 253 }
254 return node->type; 254 return node->type;
255 } break; 255 } break;
256 case NODE_IF: {
257 Type type = type_inference(a, node->cond_if, scope);
258 if (!str_eq(type, cstr("bool"))) {
259 emit_semantic_error(
260 a, node->cond_if,
261 cstr("non boolean expression on if condition"));
262 return cstr("");
263 }
264 if (node->cond_expr->kind == NODE_BLOCK) {
265 node->type = type_inference(a, node->cond_expr, scope);
266 } else {
267 TypeScope *next = typescope_alloc(a, scope);
268 node->type = type_inference(a, node->cond_expr, next);
269 }
270 if (node->cond_else) {
271 Type else_type;
272 if (node->cond_else->kind == NODE_BLOCK) {
273 else_type = type_inference(a, node->cond_else, scope);
274 } else {
275 TypeScope *next = typescope_alloc(a, scope);
276 else_type = type_inference(a, node->cond_else, next);
277 }
278 if (!str_eq(node->type, else_type)) {
279 emit_semantic_error(
280 a, node,
281 cstr("mismatch types for if/else branches"));
282 return cstr("");
283 }
284 }
285 } break;
256 case NODE_TRUE: 286 case NODE_TRUE:
257 case NODE_FALSE: { 287 case NODE_FALSE: {
258 node->type = cstr("bool"); 288 node->type = cstr("bool");