Warn when non-void methods and closures finish without returning
Build / AerScript (push) Successful in 40s
Build / AerScript (push) Successful in 40s
This commit is contained in:
@@ -2723,6 +2723,14 @@ Resume:
|
||||
*/
|
||||
case PH7_OP_DONE:
|
||||
bReturning = pInstr->p3 != 0;
|
||||
/* Only normal fallthrough of a function body requires a result.
|
||||
* Keep the call's NULL result unconverted, unlike explicit return. */
|
||||
if(!pInstr->iP1 && pInstr->iP2 && (pEntryFrame->iFlags & VM_FRAME_ACTIVE) && (pEntryFrame->iFlags & VM_FRAME_THROW) == 0) {
|
||||
ph7_vm_func *pFunc = (ph7_vm_func *)pEntryFrame->pUserData;
|
||||
if(pFunc->nType && (pFunc->nType & MEMOBJ_VOID) == 0) {
|
||||
PH7_VmThrowError(&(*pVm), PH7_CTX_WARNING, "Missing return value in closure/method returning non-void");
|
||||
}
|
||||
}
|
||||
if(bReturning && !pInstr->iP1 && (iExecFlags & VM_EXEC_INCLUDE) && pResult) {
|
||||
PH7_MemObjRelease(pResult);
|
||||
MemObjSetType(pResult, MEMOBJ_NULL);
|
||||
|
||||
Reference in New Issue
Block a user