From 9cae9eb9055749c0d8393045809cb307a551825b Mon Sep 17 00:00:00 2001 From: belliash Date: Sun, 22 Jul 2018 21:41:33 +0200 Subject: [PATCH] Throw an error if it cannot match the overloaded function/method. This fixes #13. --- engine/vm.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/engine/vm.c b/engine/vm.c index 1f7b1d0..cf57482 100644 --- a/engine/vm.c +++ b/engine/vm.c @@ -630,6 +630,9 @@ static int VmOverloadCompare(SyString *pFirst, SyString *pSecond) { } return (int)(zFin - zPtr); } +/* Forward declaration */ +static sxi32 VmLocalExec(ph7_vm *pVm, SySet *pByteCode, ph7_value *pResult); +static sxi32 VmErrorFormat(ph7_vm *pVm, sxi32 iErr, const char *zFormat, ...); /* * Select the appropriate VM function for the current call context. * This is the implementation of the powerful 'function overloading' feature @@ -662,8 +665,8 @@ static ph7_vm_func *VmOverload( pLink = pLink->pNextName; } if(i < 1) { - /* No candidates,return the head of the list */ - return pList; + /* No candidates, throw an error */ + VmErrorFormat(&(*pVm), PH7_CTX_ERR, "Invalid number of arguments passed to function/method '%s'", pList->sName); } if(nArg < 1 || i < 2) { /* Return the only candidate */ @@ -715,9 +718,6 @@ static ph7_vm_func *VmOverload( /* Appropriate function for the current call context */ return apSet[iTarget]; } -/* Forward declaration */ -static sxi32 VmLocalExec(ph7_vm *pVm, SySet *pByteCode, ph7_value *pResult); -static sxi32 VmErrorFormat(ph7_vm *pVm, sxi32 iErr, const char *zFormat, ...); /* * Mount a compiled class into the freshly created vitual machine so that * it can be instanciated from the executed PHP script.