- added an error check for duplicate local variable definitions.

Note that this only applies if both are in the same block. Just like in C++, it is perfectly legal to have the same variable name in two different nested scopes.
This commit is contained in:
Christoph Oelckers 2016-12-03 12:33:58 +01:00
parent b3783a3850
commit 136e976b2a
1 changed files with 13 additions and 0 deletions

View File

@ -9975,6 +9975,19 @@ FxExpression *FxLocalVariableDeclaration::Resolve(FCompileContext &ctx)
if (Init) Init = new FxTypeCast(Init, ValueType, false);
SAFE_RESOLVE_OPT(Init, ctx);
}
if (Name != NAME_None)
{
for (auto l : ctx.Block->LocalVars)
{
if (l->Name == Name)
{
ScriptPosition.Message(MSG_ERROR, "Local variable %s already defined", Name.GetChars());
l->ScriptPosition.Message(MSG_ERROR, "Original definition is here ");
delete this;
return nullptr;
}
}
}
ctx.Block->LocalVars.Push(this);
return this;
}