diff --git a/src/plasp/pddl/Domain.cpp b/src/plasp/pddl/Domain.cpp index b8c06a0..d1492b3 100644 --- a/src/plasp/pddl/Domain.cpp +++ b/src/plasp/pddl/Domain.cpp @@ -352,15 +352,32 @@ void Domain::checkConsistency() m_requirements.push_back(Requirement(Requirement::Type::Typing)); } - // Verify that all variables and constants have types + // Verify that all variables and constants have types if and only if typing enabled if (hasRequirement(Requirement::Type::Typing)) { + const auto acceptType = + [&](const auto *type) + { + return ((type == nullptr) != hasRequirement(Requirement::Type::Typing)); + }; + std::for_each(m_constants.cbegin(), m_constants.cend(), [&](const auto &constant) { - if (constant->type() == nullptr) + if (!acceptType(constant->type())) throw ConsistencyException("Constant \"" + constant->name() + "\" has no type"); }); + + std::for_each(m_predicateDeclarations.cbegin(), m_predicateDeclarations.cend(), + [&](const auto &predicateDeclaration) + { + std::for_each(predicateDeclaration->arguments().cbegin(), predicateDeclaration->arguments().cend(), + [&](const auto &argument) + { + if (!acceptType(argument->type())) + throw ConsistencyException("Variable \"" + argument->name() + "\" has no type"); + }); + }); } // Verify that all used types have been declared diff --git a/src/plasp/pddl/expressions/Variable.cpp b/src/plasp/pddl/expressions/Variable.cpp index 4317a28..c55d02e 100644 --- a/src/plasp/pddl/expressions/Variable.cpp +++ b/src/plasp/pddl/expressions/Variable.cpp @@ -27,7 +27,8 @@ namespace expressions //////////////////////////////////////////////////////////////////////////////////////////////////// Variable::Variable() -: m_isDirty{false} +: m_isDirty{false}, + m_type{nullptr} { }