Checking that all variables in predicates have types if and only if typing is enabled.
This commit is contained in:
parent
4228ca01dc
commit
e6ddad5960
@ -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
|
||||
|
@ -27,7 +27,8 @@ namespace expressions
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Variable::Variable()
|
||||
: m_isDirty{false}
|
||||
: m_isDirty{false},
|
||||
m_type{nullptr}
|
||||
{
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user