Browse Source

Verify that return value match the data type of declared method/closure.

pull/50/head
Rafal Kupiec 2 years ago
parent
commit
c8985032ef
Signed by: belliash GPG Key ID: 4E829243E0CFE6B4
1 changed files with 12 additions and 0 deletions
  1. +12
    -0
      engine/vm.c

+ 12
- 0
engine/vm.c View File

@ -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) {


Loading…
Cancel
Save