From 4baeaff70514edfee0209952bf58d8d8233b471b Mon Sep 17 00:00:00 2001 From: Sofia Date: Mon, 13 Apr 2026 18:26:47 +0300 Subject: [PATCH] Add rest of typechecking --- src/typechecker.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/typechecker.cpp b/src/typechecker.cpp index b0fa3ac..febc46d 100644 --- a/src/typechecker.cpp +++ b/src/typechecker.cpp @@ -99,6 +99,9 @@ namespace AST { if (binop) { return binop->result; } + + // TODO check for binops that may be implicitly castable + state.errors.push_back(CompileError( "No suitable binop between " + lhs_ty->formatted() + " " @@ -170,10 +173,12 @@ namespace AST { } void IfStatement::typecheck(typecheck::State& state, typecheck::Scope& scope) { - auto bool_ty_ptr = new types::FundamentalType{ types::FundamentalTypeKind::Bool }; - this->m_condition->typecheck(state, scope, std::shared_ptr{ bool_ty_ptr }); + auto bool_ty = std::shared_ptr{ + new types::FundamentalType{ types::FundamentalTypeKind::Bool } }; + auto expr_ty = this->m_condition->typecheck(state, scope, bool_ty); - // TODO check that condition really is a boolean + auto check_res = check_type(expr_ty, bool_ty); + this->m_condition = handle_res(std::move(this->m_condition), check_res, state); this->m_then->typecheck(state, scope); if (this->m_else) {