From d6b730945cb67bc0f20f0f8aa5afefea6e61707c Mon Sep 17 00:00:00 2001 From: Sofia Date: Mon, 13 Apr 2026 18:17:33 +0300 Subject: [PATCH] Check binops --- src/typechecker.cpp | 24 ++++++++++++++++++++++-- src/typechecker.h | 2 ++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/typechecker.cpp b/src/typechecker.cpp index fb2826e..b0fa3ac 100644 --- a/src/typechecker.cpp +++ b/src/typechecker.cpp @@ -85,9 +85,29 @@ namespace AST { auto lhs_ty = this->m_lhs->typecheck(state, scope, {}); auto rhs_ty = this->m_rhs->typecheck(state, scope, {}); - // TODO actually check binop types properly + if (this->m_binop == types::BinOp::Assignment) { + return lhs_ty; + } - return lhs_ty; + auto binop = types::find_binop( + state.binops, + lhs_ty, + this->m_binop, + rhs_ty + ); + + if (binop) { + return binop->result; + } + state.errors.push_back(CompileError( + "No suitable binop between " + + lhs_ty->formatted() + " " + + types::format_operator(this->m_binop) + " " + + rhs_ty->formatted(), + this->m_meta)); + + return std::shared_ptr{ + new types::FundamentalType{ types::FundamentalTypeKind::Void } }; } std::shared_ptr FunctionCallExpression::typecheck( diff --git a/src/typechecker.h b/src/typechecker.h index 528c720..e234aea 100644 --- a/src/typechecker.h +++ b/src/typechecker.h @@ -4,6 +4,7 @@ #include #include "types.h" +#include "binops.h" #include "errors.h" namespace typecheck { @@ -13,6 +14,7 @@ namespace typecheck { }; struct State { + std::vector binops; std::vector errors; }; }