Copy all attributes from base classes and emit a warning if redeclared in subclass.
The build was successful. Details

This commit is contained in:
Rafal Kupiec 2019-05-17 06:52:29 +02:00
parent e8c675bd8e
commit 48ccd7fef0
Signed by: belliash
GPG Key ID: 4E829243E0CFE6B4
1 changed files with 3 additions and 7 deletions

View File

@ -247,18 +247,14 @@ PH7_PRIVATE sxi32 PH7_ClassInherit(ph7_vm *pVm, ph7_class *pSub, ph7_class *pBas
if(rc != SXRET_OK) { if(rc != SXRET_OK) {
return rc; return rc;
} }
/* Copy public/protected attributes from the base class */ /* Copy all attributes from the base class */
SyHashResetLoopCursor(&pBase->hAttr); SyHashResetLoopCursor(&pBase->hAttr);
while((pEntry = SyHashGetNextEntry(&pBase->hAttr)) != 0) { while((pEntry = SyHashGetNextEntry(&pBase->hAttr)) != 0) {
/* Make sure the private attributes are not redeclared in the subclass */ /* Check if attributes are not being redeclared in the subclass and emit WARNING */
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 && ((ph7_class_attr *)pEntry->pUserData)->iProtection != PH7_CLASS_PROT_PUBLIC) { PH7_VmThrowError(pVm, PH7_CTX_WARNING, "Attribute '%z::$%z' hides inherited member '%z::$%z'", &pSub->sName, pName, &pBase->sName, pName);
/* Cannot redeclare private attribute */
PH7_VmThrowError(pVm, PH7_CTX_ERR, "Private attribute '%z::%z' redeclared inside child class '%z'", &pBase->sName, pName, &pSub->sName);
}
continue;
} }
/* Install the attribute */ /* Install the attribute */
rc = SyHashInsert(&pSub->hAttr, (const void *)pName->zString, pName->nByte, pAttr); rc = SyHashInsert(&pSub->hAttr, (const void *)pName->zString, pName->nByte, pAttr);