From 61440392d22816d87d57311a705981e5d0095458 Mon Sep 17 00:00:00 2001 From: melex750 Date: Tue, 5 Apr 2016 14:00:15 -0400 Subject: [PATCH 1/2] Fix initializing static array in class definition issue #32 --- src/CBot/CBotClass.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/CBot/CBotClass.cpp b/src/CBot/CBotClass.cpp index 27794d7f..1995dd9c 100644 --- a/src/CBot/CBotClass.cpp +++ b/src/CBot/CBotClass.cpp @@ -739,8 +739,15 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond) if ( pv->IsStatic() && pv->m_InitExpr != nullptr ) { CBotStack* pile = CBotStack::AllocateStack(); // independent stack - while(pile->IsOk() && !pv->m_InitExpr->Execute(pile)); // evaluates the expression without timer - pv->SetVal( pile->GetVar() ) ; + if ( type2.Eq(CBotTypArrayPointer) ) + { + while(pile->IsOk() && !pv->m_InitExpr->Execute(pile, pv)); + } + else + { + while(pile->IsOk() && !pv->m_InitExpr->Execute(pile)); // evaluates the expression without timer + pv->SetVal( pile->GetVar() ) ; + } pile->Delete(); } } From 748f0034bd613f587607be9e761cca0347d06059 Mon Sep 17 00:00:00 2001 From: melex750 Date: Tue, 5 Apr 2016 14:28:36 -0400 Subject: [PATCH 2/2] Fix array in a class not working with sizeof()... ...when no assignment is made in the definition. It should pass this unit test now: TEST_F(CBotUT, DISABLED_ArraysInClasses) --- src/CBot/CBotClass.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/CBot/CBotClass.cpp b/src/CBot/CBotClass.cpp index 1995dd9c..70c72ef5 100644 --- a/src/CBot/CBotClass.cpp +++ b/src/CBot/CBotClass.cpp @@ -22,6 +22,7 @@ #include "CBot/CBotInstr/CBotInstrUtils.h" #include "CBot/CBotInstr/CBotNew.h" #include "CBot/CBotInstr/CBotLeftExprVar.h" +#include "CBot/CBotInstr/CBotExprLitNull.h" #include "CBot/CBotInstr/CBotTwoOpExpr.h" #include "CBot/CBotInstr/CBotFunction.h" #include "CBot/CBotInstr/CBotExpression.h" @@ -722,6 +723,7 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond) } if ( !pStack->IsOk() ) return false; } + else if ( type2.Eq(CBotTypArrayPointer) ) i = new CBotExprLitNull(); if ( !bSecond )