patrick
/
plasp
Archived
1
0
Fork 0

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
1 changed files with 10 additions and 0 deletions

View File

@ -45,6 +45,16 @@ void Variable::parseDeclaration(Context &context, Variables &parameters)
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
variable->setDirty();