I hope this finally fixes the default argument value.
The build was successful. Details

This commit is contained in:
Rafal Kupiec 2019-04-10 18:32:53 +02:00
parent 527a6ad689
commit 2a4e47e782
Signed by: belliash
GPG Key ID: 4E829243E0CFE6B4
2 changed files with 44 additions and 15 deletions

View File

@ -2891,8 +2891,10 @@ static sxi32 PH7_GenStateCollectFuncArgs(ph7_vm_func *pFunc, ph7_gen_state *pGen
if(zDup) { if(zDup) {
sArg.nType = SXU32_HIGH; /* 0xFFFFFFFF as sentinel */ sArg.nType = SXU32_HIGH; /* 0xFFFFFFFF as sentinel */
SyStringInitFromBuf(&sArg.sClass, zDup, pName->nByte); SyStringInitFromBuf(&sArg.sClass, zDup, pName->nByte);
} else {
/* This should not happen, but fallback to object anyway */
sArg.nType = MEMOBJ_OBJ;
} }
sArg.nType = MEMOBJ_OBJ;
} }
pIn++; pIn++;
if((pIn->nType & PH7_TK_OSB) && &pIn[1] < pEnd && (pIn[1].nType & PH7_TK_CSB)) { if((pIn->nType & PH7_TK_OSB) && &pIn[1] < pEnd && (pIn[1].nType & PH7_TK_CSB)) {

View File

@ -4886,7 +4886,7 @@ static sxi32 VmByteCodeExec(
} else { } else {
ph7_class_instance *pThis = (ph7_class_instance *)pArg->x.pOther; ph7_class_instance *pThis = (ph7_class_instance *)pArg->x.pOther;
/* Make sure the object is an instance of the given class */ /* Make sure the object is an instance of the given class */
if(! VmInstanceOf(pThis->pClass, pClass)) { if(pThis == 0 || !VmInstanceOf(pThis->pClass, pClass)) {
PH7_VmThrowError(&(*pVm), PH7_CTX_ERR, PH7_VmThrowError(&(*pVm), PH7_CTX_ERR,
"Argument %u passed to function '%z()' must be an object of type '%z'", "Argument %u passed to function '%z()' must be an object of type '%z'",
n+1, &pVmFunc->sName, pName); n+1, &pVmFunc->sName, pName);
@ -4986,20 +4986,47 @@ static sxi32 VmByteCodeExec(
if(rc == PH7_ABORT) { if(rc == PH7_ABORT) {
goto Abort; goto Abort;
} }
ph7_value *pTmp = PH7_ReserveMemObj(&(*pVm)); if(aFormalArg[n].nType == SXU32_HIGH) {
pTmp->iFlags = aFormalArg[n].nType; /* Argument must be a class instance [i.e: object] */
rc = PH7_MemObjSafeStore(pObj, pTmp); SyString *pName = &aFormalArg[n].sClass;
if(rc != SXRET_OK) { ph7_class *pClass;
PH7_VmThrowError(&(*pVm), PH7_CTX_ERR, /* Try to extract the desired class */
"Default value for argument %u of '%z()' does not match the data type", n + 1, &pVmFunc->sName); pClass = PH7_VmExtractClass(&(*pVm), pName->zString, pName->nByte, TRUE, 0);
if(pClass) {
if((pObj->iFlags & MEMOBJ_OBJ) == 0) {
if((pObj->iFlags & MEMOBJ_NULL) == 0) {
PH7_VmThrowError(&(*pVm), PH7_CTX_ERR,
"Default value for argument %u of '%z()' must be an object of type '%z'",
n+1, &pVmFunc->sName, pName);
PH7_MemObjRelease(pObj);
}
} else {
ph7_class_instance *pThis = (ph7_class_instance *)pObj->x.pOther;
/* Make sure the object is an instance of the given class */
if(pThis == 0 || !VmInstanceOf(pThis->pClass, pClass)) {
PH7_VmThrowError(&(*pVm), PH7_CTX_ERR,
"Default value for argument %u of '%z()' must be an object of type '%z'",
n+1, &pVmFunc->sName, pName);
PH7_MemObjRelease(pObj);
}
}
}
} else {
ph7_value *pTmp = PH7_ReserveMemObj(&(*pVm));
pTmp->iFlags = aFormalArg[n].nType;
/* Make sure the default argument is of the correct type */
rc = PH7_MemObjSafeStore(pObj, pTmp);
if(rc != SXRET_OK) {
PH7_VmThrowError(&(*pVm), PH7_CTX_ERR,
"Default value for argument %u of '%z()' does not match the data type", n + 1, &pVmFunc->sName);
}
pObj->iFlags = pTmp->iFlags;
PH7_MemObjRelease(pTmp);
/* Insert argument index */
sArg.nIdx = pObj->nIdx;
sArg.pUserData = 0;
SySetPut(&pFrame->sArg, (const void *)&sArg);
} }
pObj->iFlags = pTmp->iFlags;
PH7_MemObjRelease(pTmp);
/* Insert argument index */
sArg.nIdx = pObj->nIdx;
sArg.pUserData = 0;
SySetPut(&pFrame->sArg, (const void *)&sArg);
/* Make sure the default argument is of the correct type */
} }
} }
++n; ++n;