diff --git a/src/CBot/CBotInstr/CBotDefClass.cpp b/src/CBot/CBotInstr/CBotDefClass.cpp index 4c9ea4d4..bfd0dedf 100644 --- a/src/CBot/CBotInstr/CBotDefClass.cpp +++ b/src/CBot/CBotInstr/CBotDefClass.cpp @@ -174,7 +174,8 @@ CBotInstr* CBotDefClass::Compile(CBotToken* &p, CBotCStack* pStack, CBotClass* p CBotClass* result = pStk->GetClass(); if ( !pStk->GetTypResult(CBotVar::GetTypeMode::CLASS_AS_POINTER).Eq(CBotTypNullPointer) && ( !pStk->GetTypResult(CBotVar::GetTypeMode::CLASS_AS_POINTER).Eq(CBotTypPointer) || - ( result != nullptr && !result->IsChildOf(pClass) ))) // type compatible ? + ( result != nullptr && !(pClass->IsChildOf(result) || + result->IsChildOf(pClass))))) // type compatible ? { pStk->SetError(CBotErrBadType1, p->GetStart()); goto error; @@ -268,9 +269,10 @@ bool CBotDefClass::Execute(CBotStack* &pj) // evaluates the expression for the assignment if (!m_expr->Execute(pile)) return false; + CBotVar* pv = pile->GetVar(); + if ( bIntrincic ) { - CBotVar* pv = pile->GetVar(); if ( pv == nullptr || pv->GetPointer() == nullptr ) { pile->SetError(CBotErrNull, &m_token); @@ -280,8 +282,17 @@ bool CBotDefClass::Execute(CBotStack* &pj) } else { + if ( !(pv == nullptr || pv->GetPointer() == nullptr) ) + { + if ( !pv->GetClass()->IsChildOf(pClass)) + { + pile->SetError(CBotErrBadType1, &m_token); + return pj->Return(pile); + } + } + CBotVarClass* pInstance; - pInstance = (static_cast(pile->GetVar()))->GetPointer(); // value for the assignment + pInstance = pv->GetPointer(); // value for the assignment CBotTypResult type = pThis->GetTypResult(); pThis->SetPointer(pInstance); pThis->SetType(type); // keep pointer type