Forbid redefenition of builtin types

This commit is contained in:
2025-03-14 11:22:11 +01:00
parent ac084be7f5
commit 5d485f8505
5 changed files with 39 additions and 8 deletions

View File

@ -52,7 +52,8 @@ namespace boot
{
for (type_definition *const type : program->types)
{
if (!this->unresolved.insert({ type->identifier, std::make_shared<alias_type>() }).second)
if (!this->unresolved.insert({ type->identifier, std::make_shared<alias_type>(type->identifier) }).second
|| this->symbols->contains(type->identifier))
{
add_error<already_declared_error>(type->identifier, this->input_file, type->position());
}
@ -61,6 +62,11 @@ namespace boot
{
type->accept(this);
}
for (auto& unresolved : this->unresolved)
{
auto info = std::make_shared<type_info>(type_info(type(unresolved.second)));
this->symbols->enter(std::move(unresolved.first), info);
}
}
void declaration_visitor::visit(type_definition *definition)
@ -79,7 +85,7 @@ namespace boot
{
this->current_type = type(unresolved_alias->second);
}
else if (auto from_symbol_table = this->symbols.lookup(type_expression->name))
else if (auto from_symbol_table = this->symbols->lookup(type_expression->name))
{
this->current_type = from_symbol_table->is_type()->symbol;
}

View File

@ -247,6 +247,11 @@ namespace boot
return tag == type_tag::empty;
}
alias_type::alias_type(const std::string& name)
: name(name), reference()
{
}
pointer_type::pointer_type(type base)
: base(base)
{