Don't allow recursive structs

This commit is contained in:
Nikita Lisitsa 2025-12-18 00:54:16 +03:00
parent ddf6d55c54
commit 56c8214f36

View file

@ -194,8 +194,15 @@ namespace pslang::interpreter
if (scope.contains(struct_definition.name)) if (scope.contains(struct_definition.name))
throw std::runtime_error("Identifier \"" + struct_definition.name + "\" is already defined in this scope"); throw std::runtime_error("Identifier \"" + struct_definition.name + "\" is already defined in this scope");
auto & result = scope.structs[struct_definition.name]; struct_data result;
result.fields = struct_definition.fields; for (auto const & field : struct_definition.fields)
{
result.fields.push_back({
.name = field.name,
.type = std::make_unique<type::type>(resolve_type(context, *field.type)),
});
}
scope.structs[struct_definition.name] = std::move(result);
} }
void exec_impl(context & context, ast::statement_list_ptr const & statements) void exec_impl(context & context, ast::statement_list_ptr const & statements)