forked from Mirrors/openclonk
Prohibit overriding local vars with functions (#1831)
The old parser threw a standard compile error in this case; the AST-based parser threw an ICE, which is ultimately the same thing but made it sound like the parser was at fault. And maybe it is, and we should allow code like "local a; func a() {}" but that seems like it should be a conscious design decision.directional-lights
parent
8d2f2846b5
commit
cada67c097
|
@ -1551,7 +1551,9 @@ void C4AulCompiler::CodegenAstVisitor::visit(const ::aul::ast::VarDecl *n)
|
|||
void C4AulCompiler::CodegenAstVisitor::visit(const ::aul::ast::FunctionDecl *n)
|
||||
{
|
||||
C4PropListStatic *Parent = n->is_global ? target_host->Engine->GetPropList() : target_host->GetPropList();
|
||||
C4AulFunc *f = Parent->GetFunc(n->name.c_str());
|
||||
|
||||
C4String *name = ::Strings.FindString(n->name.c_str());
|
||||
C4AulFunc *f = Parent->GetFunc(name);
|
||||
while (f)
|
||||
{
|
||||
if (f->SFunc() && f->SFunc()->pOrgScript == host && f->Parent == Parent)
|
||||
|
@ -1563,6 +1565,11 @@ void C4AulCompiler::CodegenAstVisitor::visit(const ::aul::ast::FunctionDecl *n)
|
|||
f = f->SFunc() ? f->SFunc()->OwnerOverloaded : 0;
|
||||
}
|
||||
|
||||
if (!Fn && Parent->HasProperty(name))
|
||||
{
|
||||
throw Error(target_host, host, n, Fn, "declaration of '%s': cannot override local variable via 'func %s'", n->name.c_str(), n->name.c_str());
|
||||
}
|
||||
|
||||
assert(Fn && "CodegenAstVisitor: unable to find function definition");
|
||||
if (!Fn)
|
||||
throw Error(target_host, host, n, Fn, "internal error: unable to find function definition for %s", n->name.c_str());
|
||||
|
|
Loading…
Reference in New Issue