Fix error reporting
This commit is contained in:
parent
4bf46f1a87
commit
e47eef7d97
29
engine/oop.c
29
engine/oop.c
|
@ -218,7 +218,7 @@ PH7_PRIVATE sxi32 PH7_ClassInstallMethod(ph7_class *pClass, ph7_class_method *pM
|
||||||
* Any other return value indicates failure and the upper layer must generate an appropriate
|
* Any other return value indicates failure and the upper layer must generate an appropriate
|
||||||
* error message.
|
* error message.
|
||||||
*/
|
*/
|
||||||
PH7_PRIVATE sxi32 PH7_ClassInherit(ph7_class *pSub, ph7_class *pBase) {
|
PH7_PRIVATE sxi32 PH7_ClassInherit(ph7_vm *pVm, ph7_class *pSub, ph7_class *pBase) {
|
||||||
ph7_class_method *pMeth;
|
ph7_class_method *pMeth;
|
||||||
ph7_class_attr *pAttr;
|
ph7_class_attr *pAttr;
|
||||||
SyHashEntry *pEntry;
|
SyHashEntry *pEntry;
|
||||||
|
@ -236,12 +236,12 @@ PH7_PRIVATE sxi32 PH7_ClassInherit(ph7_class *pSub, ph7_class *pBase) {
|
||||||
pAttr = (ph7_class_attr *)pEntry->pUserData;
|
pAttr = (ph7_class_attr *)pEntry->pUserData;
|
||||||
pName = &pAttr->sName;
|
pName = &pAttr->sName;
|
||||||
if((pEntry = SyHashGet(&pSub->hAttr, (const void *)pName->zString, pName->nByte)) != 0) {
|
if((pEntry = SyHashGet(&pSub->hAttr, (const void *)pName->zString, pName->nByte)) != 0) {
|
||||||
if(pAttr->iProtection == PH7_CLASS_PROT_PRIVATE &&
|
if(pAttr->iProtection == PH7_CLASS_PROT_PRIVATE && ((ph7_class_attr *)pEntry->pUserData)->iProtection != PH7_CLASS_PROT_PUBLIC) {
|
||||||
((ph7_class_attr *)pEntry->pUserData)->iProtection != PH7_CLASS_PROT_PUBLIC) {
|
|
||||||
/* Cannot redeclare private attribute */
|
/* Cannot redeclare private attribute */
|
||||||
// PH7_GenCompileError(&(*pGen), E_WARNING, ((ph7_class_attr *)pEntry->pUserData)->nLine,
|
rc = VmErrorFormat(pVm, PH7_CTX_ERR, "Private attribute '%z::%z' redeclared inside child class '%z'", &pBase->sName, pName, &pSub->sName);
|
||||||
// "Private attribute '%z::%z' redeclared inside child class '%z'",
|
if(rc == SXERR_ABORT) {
|
||||||
// &pBase->sName, pName, &pSub->sName);
|
return SXERR_ABORT;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -261,20 +261,19 @@ PH7_PRIVATE sxi32 PH7_ClassInherit(ph7_class *pSub, ph7_class *pBase) {
|
||||||
if((pEntry = SyHashGet(&pSub->hMethod, (const void *)pName->zString, pName->nByte)) != 0) {
|
if((pEntry = SyHashGet(&pSub->hMethod, (const void *)pName->zString, pName->nByte)) != 0) {
|
||||||
if(pMeth->iFlags & PH7_CLASS_ATTR_FINAL) {
|
if(pMeth->iFlags & PH7_CLASS_ATTR_FINAL) {
|
||||||
/* Cannot Overwrite final method */
|
/* Cannot Overwrite final method */
|
||||||
// rc = PH7_GenCompileError(&(*pGen), E_ERROR, ((ph7_class_method *)pEntry->pUserData)->nLine,
|
rc = VmErrorFormat(&(*pVm), PH7_CTX_ERR, "Cannot overwrite final method '%z:%z()' inside child class '%z'", &pBase->sName, pName, &pSub->sName);
|
||||||
// "Cannot Overwrite final method '%z:%z' inside child class '%z'",
|
if(rc == SXERR_ABORT) {
|
||||||
// &pBase->sName, pName, &pSub->sName);
|
return SXERR_ABORT;
|
||||||
// if(rc == SXERR_ABORT) {
|
}
|
||||||
// return SXERR_ABORT;
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
if(pMeth->iFlags & PH7_CLASS_ATTR_ABSTRACT) {
|
if(pMeth->iFlags & PH7_CLASS_ATTR_ABSTRACT) {
|
||||||
/* Abstract method must be defined in the child class */
|
/* Abstract method must be defined in the child class */
|
||||||
// PH7_GenCompileError(&(*pGen), E_WARNING, pMeth->nLine,
|
rc = VmErrorFormat(&(*pVm), PH7_CTX_ERR, "Abstract method '%z:%z()' must be defined inside child class '%z'", &pBase->sName, pName, &pSub->sName);
|
||||||
// "Abstract method '%z:%z' must be defined inside child class '%z'",
|
if(rc == SXERR_ABORT) {
|
||||||
// &pBase->sName, pName, &pSub->sName);
|
return SXERR_ABORT;
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -627,7 +627,7 @@ static int VmOverloadCompare(SyString *pFirst, SyString *pSecond) {
|
||||||
}
|
}
|
||||||
/* Forward declaration */
|
/* Forward declaration */
|
||||||
static sxi32 VmLocalExec(ph7_vm *pVm, SySet *pByteCode, ph7_value *pResult);
|
static sxi32 VmLocalExec(ph7_vm *pVm, SySet *pByteCode, ph7_value *pResult);
|
||||||
static sxi32 VmErrorFormat(ph7_vm *pVm, sxi32 iErr, const char *zFormat, ...);
|
sxi32 VmErrorFormat(ph7_vm *pVm, sxi32 iErr, const char *zFormat, ...);
|
||||||
/*
|
/*
|
||||||
* Select the appropriate VM function for the current call context.
|
* Select the appropriate VM function for the current call context.
|
||||||
* This is the implementation of the powerful 'function overloading' feature
|
* This is the implementation of the powerful 'function overloading' feature
|
||||||
|
@ -2267,7 +2267,7 @@ static sxi32 VmThrowErrorAp(
|
||||||
* Simple boring wrapper function.
|
* Simple boring wrapper function.
|
||||||
* ------------------------------------
|
* ------------------------------------
|
||||||
*/
|
*/
|
||||||
static sxi32 VmErrorFormat(ph7_vm *pVm, sxi32 iErr, const char *zFormat, ...) {
|
sxi32 VmErrorFormat(ph7_vm *pVm, sxi32 iErr, const char *zFormat, ...) {
|
||||||
va_list ap;
|
va_list ap;
|
||||||
sxi32 rc;
|
sxi32 rc;
|
||||||
va_start(ap, zFormat);
|
va_start(ap, zFormat);
|
||||||
|
@ -4533,7 +4533,7 @@ static sxi32 VmByteCodeExec(
|
||||||
/* Trying to inherit from final class */
|
/* Trying to inherit from final class */
|
||||||
VmErrorFormat(&(*pVm), PH7_CTX_ERR, "Class '%z' cannot inherit from final class '%z'", &pClass->sName.zString, &apExtends->zString);
|
VmErrorFormat(&(*pVm), PH7_CTX_ERR, "Class '%z' cannot inherit from final class '%z'", &pClass->sName.zString, &apExtends->zString);
|
||||||
}
|
}
|
||||||
rc = PH7_ClassInherit(pClass, pBase);
|
rc = PH7_ClassInherit(pVm, pClass, pBase);
|
||||||
if(rc != SXRET_OK) {
|
if(rc != SXRET_OK) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue