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) {