Check that variables are not declared multiple times.

This commit is contained in:
Patrick Lühne 2016-06-08 13:35:10 +02:00
parent c99b7018c6
commit 1c8958ad9d

View File

@ -45,6 +45,16 @@ void Variable::parseDeclaration(Context &context, Variables &parameters)
variable->m_name = context.parser.parseIdentifier(isIdentifier); 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 &parameter)
{
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 // Flag variable for potentially upcoming type declaration
variable->setDirty(); variable->setDirty();