Check binops
This commit is contained in:
parent
bb4d1c6045
commit
d6b730945c
@ -85,11 +85,31 @@ 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;
|
||||
}
|
||||
|
||||
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(
|
||||
typecheck::State& state,
|
||||
typecheck::Scope& scope,
|
||||
|
||||
@ -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;
|
||||
};
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user