From c8985032efdadaaaa09b93aca16da8dd3974b2e5 Mon Sep 17 00:00:00 2001 From: belliash Date: Wed, 13 Mar 2019 09:36:10 +0100 Subject: [PATCH] Verify that return value match the data type of declared method/closure. --- engine/vm.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/engine/vm.c b/engine/vm.c index 2d38287..1b383a1 100644 --- a/engine/vm.c +++ b/engine/vm.c @@ -2022,6 +2022,18 @@ static sxi32 VmByteCodeExec( if(pResult) { /* Execution result */ PH7_MemObjStore(pTos, pResult); + if(pVm->pFrame->iFlags & VM_FRAME_ACTIVE) { + ph7_vm_func *pFunc = (ph7_vm_func *)pVm->pFrame->pUserData; + if(pFunc->nType) { + if((pFunc->nType & MEMOBJ_MIXED) == 0) { + if(pFunc->nType & MEMOBJ_VOID) { + PH7_VmThrowError(&(*pVm), PH7_CTX_ERR, "Return with a value in closure/method returning void"); + } else if(pFunc->nType != pResult->iFlags && PH7_CheckVarCompat(pTos, pFunc->nType) != SXRET_OK) { + PH7_VmThrowError(&(*pVm), PH7_CTX_ERR, "Incompatible type when returning data by closure/method"); + } + } + } + } } VmPopOperand(&pTos, 1); } else if(pLastRef) {