Browse Source

Report an error when trying to create an instance on interface or virtual class.

release/v0.1
Rafal Kupiec 1 year ago
parent
commit
9cc0f203ca
Signed by: belliash GPG Key ID: 4E829243E0CFE6B4
1 changed files with 5 additions and 1 deletions
  1. +5
    -1
      engine/vm.c

+ 5
- 1
engine/vm.c View File

@ -4437,7 +4437,7 @@ static sxi32 VmByteCodeExec(
if((pTos->nType & MEMOBJ_STRING) && SyBlobLength(&pTos->sBlob) > 0) {
/* Try to extract the desired class */
pClass = PH7_VmExtractClass(&(*pVm), (const char *)SyBlobData(&pTos->sBlob),
SyBlobLength(&pTos->sBlob), TRUE /* Only loadable class but not 'interface' or 'virtual' class*/);
SyBlobLength(&pTos->sBlob), FALSE);
} else if(pTos->nType & MEMOBJ_OBJ) {
/* Take the base class from the loaded instance */
pClass = ((ph7_class_instance *)pTos->x.pOther)->pClass;
@ -4448,6 +4448,10 @@ static sxi32 VmByteCodeExec(
SyBlobLength(&pTos->sBlob), (const char *)SyBlobData(&pTos->sBlob)
);
} else {
if(pClass->iFlags & (PH7_CLASS_INTERFACE | PH7_CLASS_VIRTUAL)) {
PH7_VmThrowError(&(*pVm), PH7_CTX_ERR, "Cannot create an instance of the virtual class or interface '%z'",
&pClass->sName);
}
ph7_class_method *pCons;
/* Create a new class instance */
pNew = PH7_NewClassInstance(&(*pVm), pClass);


Loading…
Cancel
Save