From 9cc0f203caa24d023cf1a3633fc4c1ee760a1cca Mon Sep 17 00:00:00 2001 From: belliash Date: Wed, 5 Jun 2019 17:41:47 +0200 Subject: [PATCH] Report an error when trying to create an instance on interface or virtual class. --- engine/vm.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/engine/vm.c b/engine/vm.c index f1733fe..665c472 100644 --- a/engine/vm.c +++ b/engine/vm.c @@ -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);