Fix wrong function index on some recursive calls

- problem: function index for recursive calls does not get updated in
  cases when the definition of the function comes before its use
- solution: treat the function as predefined until we process the whole
  of its body so that a ref gets added if a recusive call is encountered
This commit is contained in:
rhinoduck 2015-10-10 17:16:32 +02:00
parent ae5f03691a
commit ae6b71612e

12
parse.c
View file

@ -825,9 +825,19 @@ static void OuterFunction(void)
else else
{ {
sym = SY_InsertGlobal(tk_String, SY_SCRIPTFUNC); sym = SY_InsertGlobal(tk_String, SY_SCRIPTFUNC);
sym->info.scriptFunc.address = (importing == IMPORT_Importing ? 0 : pc_Address); if (importing == IMPORT_Importing)
{
sym->info.scriptFunc.address = 0;
sym->info.scriptFunc.predefined = NO; sym->info.scriptFunc.predefined = NO;
} }
else
{
sym->info.scriptFunc.address = pc_Address;
sym->info.scriptFunc.predefined = YES;
// only for consistency with other speculated functions and pretty logs
sym->info.scriptFunc.funcNumber = 0;
}
}
defLine = tk_Line; defLine = tk_Line;
TK_NextTokenMustBe(TK_LPAREN, ERR_MISSING_LPAREN); TK_NextTokenMustBe(TK_LPAREN, ERR_MISSING_LPAREN);