Check binops

This commit is contained in:
Sofia 2026-04-13 18:17:33 +03:00
parent bb4d1c6045
commit d6b730945c
2 changed files with 24 additions and 2 deletions

View File

@ -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<types::Type>{
new types::FundamentalType{ types::FundamentalTypeKind::Void } };
}
std::shared_ptr<types::Type> FunctionCallExpression::typecheck(

View File

@ -4,6 +4,7 @@
#include <map>
#include "types.h"
#include "binops.h"
#include "errors.h"
namespace typecheck {
@ -13,6 +14,7 @@ namespace typecheck {
};
struct State {
std::vector<types::BinopDefinition> binops;
std::vector<CompileError> errors;
};
}