From 37ab015c8db1c29cbd01e849fd6cc586b60c794d Mon Sep 17 00:00:00 2001 From: melex750 Date: Sun, 29 May 2016 06:55:28 -0400 Subject: [PATCH] Fix conversion to string with = operator --- src/CBot/CBotInstr/CBotExpression.cpp | 23 +++++++++++++++++++++-- src/CBot/CBotInstr/CBotLeftExprVar.cpp | 6 ++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/CBot/CBotInstr/CBotExpression.cpp b/src/CBot/CBotInstr/CBotExpression.cpp index cb7f3dfc..c98deca5 100644 --- a/src/CBot/CBotInstr/CBotExpression.cpp +++ b/src/CBot/CBotInstr/CBotExpression.cpp @@ -71,6 +71,13 @@ CBotInstr* CBotExpression::Compile(CBotToken* &p, CBotCStack* pStack) return nullptr; } + if ( p->GetType() == ID_SEP ) + { + pStack->SetError(CBotErrNoExpression, p); + delete inst; + return nullptr; + } + inst->m_rightop = CBotExpression::Compile(p, pStack); if (inst->m_rightop == nullptr) { @@ -118,13 +125,13 @@ CBotInstr* CBotExpression::Compile(CBotToken* &p, CBotCStack* pStack) break; case ID_ASSADD: if (type2.Eq(CBotTypBoolean) || - type2.Eq(CBotTypPointer) ) type2 = -1; // numbers and strings + type2.GetType() > CBotTypString ) type2.SetType(-1); // numbers and strings break; case ID_ASSSUB: case ID_ASSMUL: case ID_ASSDIV: case ID_ASSMODULO: - if (type2.GetType() >= CBotTypBoolean) type2 = -1; // numbers only + if (type2.GetType() >= CBotTypBoolean) type2.SetType(-1); // numbers only break; } @@ -179,6 +186,18 @@ bool CBotExpression::Execute(CBotStack* &pj) if ( pile2->GetState()==0) { if (m_rightop && !m_rightop->Execute(pile2)) return false; // initial value // interrupted? + if (m_rightop) + { + CBotVar* var = pile1->GetVar(); + CBotVar* value = pile2->GetVar(); + if (var->GetType() == CBotTypString && value->GetType() != CBotTypString) + { + CBotVar* newVal = CBotVar::Create("", var->GetTypResult()); + value->Update(pj->GetUserPtr()); + newVal->SetValString(value->GetValString()); + pile2->SetVar(newVal); + } + } pile2->IncState(); } diff --git a/src/CBot/CBotInstr/CBotLeftExprVar.cpp b/src/CBot/CBotInstr/CBotLeftExprVar.cpp index 848d16a8..4394fc43 100644 --- a/src/CBot/CBotInstr/CBotLeftExprVar.cpp +++ b/src/CBot/CBotInstr/CBotLeftExprVar.cpp @@ -64,6 +64,12 @@ bool CBotLeftExprVar::Execute(CBotStack* &pj) CBotVar* var2 = pj->GetVar(); // Initial value on the stack if (var2 != nullptr) { + if (m_typevar.Eq(CBotTypString) && var2->GetType() != CBotTypString) + { + var2->Update(pj->GetUserPtr()); + var1->SetValString(var2->GetValString()); + return true; + } var1->SetVal(var2); // Set the value }