- 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

View file

@ -9975,6 +9975,19 @@ FxExpression *FxLocalVariableDeclaration::Resolve(FCompileContext &ctx)
if (Init) Init = new FxTypeCast(Init, ValueType, false); if (Init) Init = new FxTypeCast(Init, ValueType, false);
SAFE_RESOLVE_OPT(Init, ctx); 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); ctx.Block->LocalVars.Push(this);
return this; return this;
} }