diff --git a/lib/libimhex/include/hex/pattern_language/ast/ast_node_type_decl.hpp b/lib/libimhex/include/hex/pattern_language/ast/ast_node_type_decl.hpp index 9a7c4a486..35d4795f2 100644 --- a/lib/libimhex/include/hex/pattern_language/ast/ast_node_type_decl.hpp +++ b/lib/libimhex/include/hex/pattern_language/ast/ast_node_type_decl.hpp @@ -25,11 +25,16 @@ namespace hex::pl { void setName(const std::string &name) { this->m_name = name; } [[nodiscard]] const std::string &getName() const { return this->m_name; } - [[nodiscard]] const std::shared_ptr &getType() { return this->m_type; } + [[nodiscard]] const std::shared_ptr &getType() const { + if (this->isForwardDeclared()) + LogConsole::abortEvaluation(hex::format("cannot use incomplete type '{}'", this->m_name), this); + + return this->m_type; + } [[nodiscard]] std::optional getEndian() const { return this->m_endian; } [[nodiscard]] std::unique_ptr evaluate(Evaluator *evaluator) const override { - auto type = this->m_type->evaluate(evaluator); + auto type = this->getType()->evaluate(evaluator); if (auto attributable = dynamic_cast(type.get())) { for (auto &attribute : this->getAttributes()) { @@ -45,7 +50,7 @@ namespace hex::pl { } [[nodiscard]] std::vector> createPatterns(Evaluator *evaluator) const override { - auto patterns = this->m_type->createPatterns(evaluator); + auto patterns = this->getType()->createPatterns(evaluator); for (auto &pattern : patterns) { if (pattern == nullptr) @@ -64,7 +69,7 @@ namespace hex::pl { } void addAttribute(std::unique_ptr &&attribute) override { - if (auto attributable = dynamic_cast(this->m_type.get()); attributable != nullptr) { + if (auto attributable = dynamic_cast(this->getType().get()); attributable != nullptr) { attributable->addAttribute(std::unique_ptr(static_cast(attribute->clone().release()))); }