Check that variables are not declared multiple times.
This commit is contained in:
parent
c99b7018c6
commit
1c8958ad9d
@ -45,6 +45,16 @@ void Variable::parseDeclaration(Context &context, Variables ¶meters)
|
|||||||
|
|
||||||
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 ¶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
|
// Flag variable for potentially upcoming type declaration
|
||||||
variable->setDirty();
|
variable->setDirty();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user