diff --git a/src/CBot/CBotInstr/CBotDefArray.cpp b/src/CBot/CBotInstr/CBotDefArray.cpp index 473fdc8d..c1995d92 100644 --- a/src/CBot/CBotInstr/CBotDefArray.cpp +++ b/src/CBot/CBotInstr/CBotDefArray.cpp @@ -121,6 +121,15 @@ CBotInstr* CBotDefArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResul } } } + + if (pStk->IsOk()) while (true) // mark initialized + { + var = var->GetItem(0, true); + if (var == nullptr) break; + if (var->GetType() == CBotTypArrayPointer) continue; + if (var->GetType() <= CBotTypString) var->SetInit(CBotVar::InitType::DEF); + break; + } } if (pStk->IsOk()) return pStack->Return(inst, pStk); diff --git a/src/CBot/CBotInstr/CBotInstrMethode.cpp b/src/CBot/CBotInstr/CBotInstrMethode.cpp index e0d08a99..3bdf8492 100644 --- a/src/CBot/CBotInstr/CBotInstrMethode.cpp +++ b/src/CBot/CBotInstr/CBotInstrMethode.cpp @@ -103,6 +103,7 @@ bool CBotInstrMethode::ExecuteVar(CBotVar* &pVar, CBotStack* &pj, CBotToken* pre if (pVar->GetPointer() == nullptr) { pj->SetError(CBotErrNull, prevToken); + return pj->Return(pile1); } if (pile1->IfStep()) return false; diff --git a/src/CBot/CBotInstr/CBotListArray.cpp b/src/CBot/CBotInstr/CBotListArray.cpp index 559bb9d9..89cbb79a 100644 --- a/src/CBot/CBotInstr/CBotListArray.cpp +++ b/src/CBot/CBotInstr/CBotListArray.cpp @@ -98,7 +98,7 @@ CBotInstr* CBotListArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResu } } - inst->m_expr->AddNext3(i); + inst->m_expr->AddNext3b(i); if ( p->GetType() == ID_COMMA ) continue; if ( p->GetType() == ID_CLBLK ) break; @@ -114,10 +114,10 @@ CBotInstr* CBotListArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResu { goto error; } - CBotVar* pv = pStk->GetVar(); // result of the expression - if (pv == nullptr || (!TypesCompatibles( type, pv->GetTypResult()) && - !(type.Eq(CBotTypPointer) && pv->GetTypResult().Eq(CBotTypNullPointer)) )) + CBotTypResult valType = pStk->GetTypResult(); + + if (!TypeCompatible(valType, type, ID_ASS) ) { pStk->SetError(CBotErrBadType1, p->GetStart()); goto error; @@ -133,15 +133,14 @@ CBotInstr* CBotListArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResu goto error; } - CBotVar* pv = pStk->GetVar(); // result of the expression + CBotTypResult valType = pStk->GetTypResult(); - if (pv == nullptr || (!TypesCompatibles( type, pv->GetTypResult()) && - !(type.Eq(CBotTypPointer) && pv->GetTypResult().Eq(CBotTypNullPointer)) )) + if (!TypeCompatible(valType, type, ID_ASS) ) { pStk->SetError(CBotErrBadType1, p->GetStart()); goto error; } - inst->m_expr->AddNext3(i); + inst->m_expr->AddNext3b(i); if (p->GetType() == ID_COMMA) continue; if (p->GetType() == ID_CLBLK) break; @@ -175,7 +174,7 @@ bool CBotListArray::Execute(CBotStack* &pj, CBotVar* pVar) int n = 0; - for (; p != nullptr ; n++, p = p->GetNext3()) + for (; p != nullptr ; n++, p = p->GetNext3b()) { if (pile1->GetState() > n) continue; @@ -207,7 +206,7 @@ void CBotListArray::RestoreState(CBotStack* &pj, bool bMain) int state = pile->GetState(); - while(state-- > 0) p = p->GetNext3() ; + while(state-- > 0) p = p->GetNext3b() ; p->RestoreState(pile, bMain); // size calculation //interrupted! } diff --git a/src/CBot/CBotInstr/CBotListArray.h b/src/CBot/CBotInstr/CBotListArray.h index c5f800b0..18d6b567 100644 --- a/src/CBot/CBotInstr/CBotListArray.h +++ b/src/CBot/CBotInstr/CBotListArray.h @@ -62,7 +62,7 @@ protected: virtual std::map GetDebugLinks() override; private: - //! An expression for an element others are linked with CBotInstr :: m_next3; + //! An expression for an element others are linked with CBotInstr :: m_next3b; CBotInstr* m_expr; }; diff --git a/src/CBot/CBotInstr/CBotNew.cpp b/src/CBot/CBotInstr/CBotNew.cpp index 7da8e417..a302b394 100644 --- a/src/CBot/CBotInstr/CBotNew.cpp +++ b/src/CBot/CBotInstr/CBotNew.cpp @@ -50,7 +50,11 @@ CBotInstr* CBotNew::Compile(CBotToken* &p, CBotCStack* pStack) if (!IsOfType(p, ID_NEW)) return nullptr; // verifies that the token is a class name - if (p->GetType() != TokenTypVar) return nullptr; + if (p->GetType() != TokenTypVar) + { + pStack->SetError(CBotErrBadNew, p); + return nullptr; + } CBotClass* pClass = CBotClass::Find(p); if (pClass == nullptr) diff --git a/src/CBot/CBotProgram.cpp b/src/CBot/CBotProgram.cpp index dde36bb4..d0284ea2 100644 --- a/src/CBot/CBotProgram.cpp +++ b/src/CBot/CBotProgram.cpp @@ -214,6 +214,7 @@ bool CBotProgram::Run(void* pUser, int timer) m_error = m_stack->GetError(m_errorStart, m_errorEnd); m_stack->Delete(); m_stack = nullptr; + CBotClass::FreeLock(this); return true; // execution is finished! } @@ -226,6 +227,7 @@ void CBotProgram::Stop() m_stack->Delete(); m_stack = nullptr; m_entryPoint = nullptr; + CBotClass::FreeLock(this); } ////////////////////////////////////////////////////////////////////////////////