From da85e5dd9b352cd75866746dfb567528a0fcf489 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20L=C3=BChne?= Date: Mon, 13 Jun 2016 16:37:35 +0200 Subject: [PATCH] Checking whether variables have types before accessing them in the PDDL translator. --- src/plasp/pddl/TranslatorASP.cpp | 15 +++++++++++++-- tests/data/issues/issue-4.pddl | 11 +++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 tests/data/issues/issue-4.pddl diff --git a/src/plasp/pddl/TranslatorASP.cpp b/src/plasp/pddl/TranslatorASP.cpp index 6062a75..511ee70 100644 --- a/src/plasp/pddl/TranslatorASP.cpp +++ b/src/plasp/pddl/TranslatorASP.cpp @@ -40,6 +40,9 @@ void TranslatorASP::checkSupport() const std::for_each(arguments.cbegin(), arguments.cend(), [&](const auto ¶meter) { + if (parameter->type() == nullptr) + return; + if (parameter->type()->expressionType() != Expression::Type::PrimitiveType) throw utils::TranslatorException("Only primitive types supported currently"); }); @@ -56,6 +59,9 @@ void TranslatorASP::checkSupport() const std::for_each(parameters.cbegin(), parameters.cend(), [&](const auto ¶meter) { + if (parameter->type() == nullptr) + return; + if (parameter->type()->expressionType() != Expression::Type::PrimitiveType) throw utils::TranslatorException("Only primitive types supported currently"); }); @@ -391,9 +397,14 @@ void TranslatorASP::translateVariablesBody(const expressions::Variables &variabl m_ostream << ", "; const auto &variable = *dynamic_cast(i->get()); - const auto &type = *dynamic_cast(variable.type()); - m_ostream << "hasType(" << utils::escapeASPVariable(variable.name()) << ", type(" << type.name() << "))"; + if (variable.type() != nullptr) + { + const auto &type = *dynamic_cast(variable.type()); + + m_ostream << "hasType(" << utils::escapeASPVariable(variable.name()) << ", type(" << type.name() << "))"; + } + // TODO: handle untyped variables } } diff --git a/tests/data/issues/issue-4.pddl b/tests/data/issues/issue-4.pddl new file mode 100644 index 0000000..62d1f7a --- /dev/null +++ b/tests/data/issues/issue-4.pddl @@ -0,0 +1,11 @@ +(define (domain tsp) +(:requirements :negative-preconditions) + (:predicates + (at ?x) + (visited ?x) + (connected ?x ?y)) + + (:action move + :parameters (?x ?y) + :precondition (and (at ?x) (not (visited ?y)) (connected ?x ?y)) + :effect (and (at ?y) (visited ?y) (not (at ?x)))))