The compiler doesn't seem to prevent declaring two global properties with the same name. Is this by design or a bug?
Global Variable Redeclaration
Sounds like a bug. It shouldn't be allowed to exist multiple properties/variables of the same name in the same namespace. The variable name must also not conflict with a type name or the name of any function.
With global properties you mean application registered global properties? Or global variables declared from the script?
Can you give more detail on the exact scenario (to reduce my time in reproducing the problem)?
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game
I'm sorry, I mean global variables declared from the script. I find that in any script two global variable declarations compile with no errors.
double x;
double x;
void test() {
}
It doesn't look like there is any test for duplicate names in asCCompiler::CompileGlobalVariable.
as_compiler.cpp(1196):
asSExprContext compiledCtx(engine);
bool preCompiled = false;
if( gvar->datatype.IsAuto() )
preCompiled = CompileAutoType(gvar->datatype, compiledCtx, node, gvar->declaredAtNode);
if( gvar->property == 0 )
{
gvar->property = builder->module->AllocateGlobalProperty(gvar->name.AddressOf(), gvar->datatype, gvar->ns);
gvar->index = gvar->property->id;
}
as_module.cpp(1175):
asCGlobalProperty *asCModule::AllocateGlobalProperty(const char *name, const asCDataType &dt, asSNameSpace *ns)
{
asCGlobalProperty *prop = engine->AllocateGlobalProperty();
prop->name = name;
prop->nameSpace = ns;
// Allocate the memory for this property based on its type
prop->type = dt;
prop->AllocateMemory();
// Make an entry in the address to variable map
engine->varAddressMap.Insert(prop->GetAddressOfValue(), prop);
// Store the variable in the module scope (the reference count is already set to 1)
scriptGlobals.Put(prop);
return prop;
}
Thanks for the details.
The builder should definitely guarantee that no two global variables in the same namespace can have the same name. It should be done by CheckNameConflict, called by asCBuilder::RegisterGlobalVar, but I guess something has been broken recently.
I'll investigate further and have this fixed a.s.a.p.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game
I've fixed this in revision 1921.
The check for name conflict had been broken by the implementation of 'auto' types in the WIP version. For some odd reason my regression test suite didn't have a test case for this basic scenario so it wasn't detected before. But now it has so it shouldn't be broken by mistake again in the future. :)
Regards,
Andreas
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game