Check assignment type
This commit is contained in:
@ -305,6 +305,19 @@ namespace elna::source
|
||||
statement->body().accept(this);
|
||||
}
|
||||
|
||||
void type_analysis_visitor::visit(assign_statement *statement)
|
||||
{
|
||||
statement->rvalue().accept(this);
|
||||
auto lvalue_info = std::dynamic_pointer_cast<typed_info>(this->table->lookup(statement->lvalue()));
|
||||
|
||||
if (statement->rvalue().data_type != nullptr && lvalue_info->type() == statement->rvalue().data_type)
|
||||
{
|
||||
auto new_error = std::make_unique<type_mismatch>(statement->rvalue().data_type,
|
||||
type_mismatch::operation::assignment, this->filename, statement->position());
|
||||
m_errors.push_back(std::move(new_error));
|
||||
}
|
||||
}
|
||||
|
||||
const std::list<std::unique_ptr<error>>& type_analysis_visitor::errors() const noexcept
|
||||
{
|
||||
return m_errors;
|
||||
|
Reference in New Issue
Block a user