Fix implicit downcast with variable initialization
parent
c89e6f4c28
commit
6b8e240d26
|
@ -174,7 +174,8 @@ CBotInstr* CBotDefClass::Compile(CBotToken* &p, CBotCStack* pStack, CBotClass* p
|
||||||
CBotClass* result = pStk->GetClass();
|
CBotClass* result = pStk->GetClass();
|
||||||
if ( !pStk->GetTypResult(CBotVar::GetTypeMode::CLASS_AS_POINTER).Eq(CBotTypNullPointer) &&
|
if ( !pStk->GetTypResult(CBotVar::GetTypeMode::CLASS_AS_POINTER).Eq(CBotTypNullPointer) &&
|
||||||
( !pStk->GetTypResult(CBotVar::GetTypeMode::CLASS_AS_POINTER).Eq(CBotTypPointer) ||
|
( !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());
|
pStk->SetError(CBotErrBadType1, p->GetStart());
|
||||||
goto error;
|
goto error;
|
||||||
|
@ -268,9 +269,10 @@ bool CBotDefClass::Execute(CBotStack* &pj)
|
||||||
// evaluates the expression for the assignment
|
// evaluates the expression for the assignment
|
||||||
if (!m_expr->Execute(pile)) return false;
|
if (!m_expr->Execute(pile)) return false;
|
||||||
|
|
||||||
|
CBotVar* pv = pile->GetVar();
|
||||||
|
|
||||||
if ( bIntrincic )
|
if ( bIntrincic )
|
||||||
{
|
{
|
||||||
CBotVar* pv = pile->GetVar();
|
|
||||||
if ( pv == nullptr || pv->GetPointer() == nullptr )
|
if ( pv == nullptr || pv->GetPointer() == nullptr )
|
||||||
{
|
{
|
||||||
pile->SetError(CBotErrNull, &m_token);
|
pile->SetError(CBotErrNull, &m_token);
|
||||||
|
@ -280,8 +282,17 @@ bool CBotDefClass::Execute(CBotStack* &pj)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if ( !(pv == nullptr || pv->GetPointer() == nullptr) )
|
||||||
|
{
|
||||||
|
if ( !pv->GetClass()->IsChildOf(pClass))
|
||||||
|
{
|
||||||
|
pile->SetError(CBotErrBadType1, &m_token);
|
||||||
|
return pj->Return(pile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
CBotVarClass* pInstance;
|
CBotVarClass* pInstance;
|
||||||
pInstance = (static_cast<CBotVarPointer*>(pile->GetVar()))->GetPointer(); // value for the assignment
|
pInstance = pv->GetPointer(); // value for the assignment
|
||||||
CBotTypResult type = pThis->GetTypResult();
|
CBotTypResult type = pThis->GetTypResult();
|
||||||
pThis->SetPointer(pInstance);
|
pThis->SetPointer(pInstance);
|
||||||
pThis->SetType(type); // keep pointer type
|
pThis->SetType(type); // keep pointer type
|
||||||
|
|
Loading…
Reference in New Issue