diff --git a/src/plasp/pddl/expressions/Variable.cpp b/src/plasp/pddl/expressions/Variable.cpp index 05c2b57..25cfa06 100644 --- a/src/plasp/pddl/expressions/Variable.cpp +++ b/src/plasp/pddl/expressions/Variable.cpp @@ -45,6 +45,16 @@ void Variable::parseDeclaration(Context &context, Variables ¶meters) variable->m_name = context.parser.parseIdentifier(isIdentifier); + // Check if variable of that name already exists in the current scope + const auto match = std::find_if(parameters.cbegin(), parameters.cend(), + [&](const auto ¶meter) + { + return parameter->name() == variable->m_name; + }); + + if (match != parameters.cend()) + throw utils::ParserException(context.parser, "Variable \"" + variable->m_name + "\" already declared in this scope"); + // Flag variable for potentially upcoming type declaration variable->setDirty();