Fix implicit downcast with variable initialization

dev-new-models
Jeremy Mickelson 2016-08-07 08:27:01 -04:00 committed by melex750
parent c89e6f4c28
commit 6b8e240d26
1 changed files with 14 additions and 3 deletions

View File

@ -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<CBotVarPointer*>(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