diff --git a/module.cpp b/module.cpp index 436791e6..17df7b86 100644 --- a/module.cpp +++ b/module.cpp @@ -792,11 +792,13 @@ void Module::AddFunctionDefinition(const std::string &name, const FunctionType *type, Stmt *code) { Symbol *sym = symbolTable->LookupFunction(name.c_str(), type); - if (sym == NULL) { + if (sym == NULL || code == NULL) { Assert(m->errorCount > 0); return; } + sym->pos = code->pos; + // FIXME: because we encode the parameter names in the function type, // we need to override the function type here in case the function had // earlier been declared with anonymous parameter names but is now diff --git a/parse.yy b/parse.yy index c4db2fa9..f7a468ad 100644 --- a/parse.yy +++ b/parse.yy @@ -1862,8 +1862,11 @@ function_definition dynamic_cast($2->type); if (funcType == NULL) Assert(m->errorCount > 0); - else - m->AddFunctionDefinition($2->name, funcType, $4); + else { + Stmt *code = $4; + if (code == NULL) code = new StmtList(@4); + m->AddFunctionDefinition($2->name, funcType, code); + } } m->symbolTable->PopScope(); // push in lAddFunctionParams(); }