[colobot] 201/377: Fixed object:: with other types (#207)

Didier Raboud odyx at moszumanska.debian.org
Wed Mar 30 13:34:16 UTC 2016


This is an automated email from the git hooks/post-receive script.

odyx pushed a commit to branch debian/master
in repository colobot.

commit 0807b75d4b3d63526220bf54348ab70bad456cb8
Author: krzys-h <krzys_h at interia.pl>
Date:   Fri Dec 25 15:13:52 2015 +0100

    Fixed object:: with other types (#207)
---
 src/CBot/CBotInstr/CBotFunction.cpp | 17 +++++++++++++++--
 src/CBot/CBotInstr/CBotFunction.h   |  4 +++-
 2 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/src/CBot/CBotInstr/CBotFunction.cpp b/src/CBot/CBotInstr/CBotFunction.cpp
index 59da2d4..8be758f 100644
--- a/src/CBot/CBotInstr/CBotFunction.cpp
+++ b/src/CBot/CBotInstr/CBotFunction.cpp
@@ -178,6 +178,7 @@ CBotFunction* CBotFunction::Compile(CBotToken* &p, CBotCStack* pStack, CBotFunct
             if ( IsOfType( p, ID_DBLDOTS ) )        // method for a class
             {
                 func->m_MasterClass = pp->GetString();
+                func->m_classToken = *pp;
                 CBotClass* pClass = CBotClass::Find(pp);
                 if ( pClass == nullptr ) goto bad;
 
@@ -355,10 +356,16 @@ bool CBotFunction::Execute(CBotVar** ppVars, CBotStack* &pj, CBotVar* pInstance)
         }
         else
         {
+            if (m_MasterClass != pInstance->GetClass()->GetName())
+            {
+                pile->SetError(CBotErrBadType2, &m_classToken);
+                return false;
+            }
+
             pThis = CBotVar::Create("this", CBotTypResult( CBotTypPointer, m_MasterClass ));
             pThis->SetPointer(pInstance);
         }
-        assert(pThis);
+        assert(pThis != nullptr);
         pThis->SetInit(CBotVar::InitType::IS_POINTER);
 
 //      pThis->SetUniqNum(m_nThisIdent);
@@ -617,10 +624,16 @@ int CBotFunction::DoCall(long& nIdent, const std::string& name, CBotVar** ppVars
                 }
                 else
                 {
+                    if (pt->m_MasterClass != pInstance->GetClass()->GetName())
+                    {
+                        pStack->SetError(CBotErrBadType2, &pt->m_classToken);
+                        return false;
+                    }
+
                     pThis = CBotVar::Create("this", CBotTypResult( CBotTypPointer, pt->m_MasterClass ));
                     pThis->SetPointer(pInstance);
                 }
-                assert(pThis);
+                assert(pThis != nullptr);
                 pThis->SetInit(CBotVar::InitType::IS_POINTER);
 
                 pThis->SetUniqNum(-2);
diff --git a/src/CBot/CBotInstr/CBotFunction.h b/src/CBot/CBotInstr/CBotFunction.h
index 216e19a..5547b68 100644
--- a/src/CBot/CBotInstr/CBotFunction.h
+++ b/src/CBot/CBotInstr/CBotFunction.h
@@ -261,8 +261,10 @@ private:
     bool m_bPublic;
     //! Extern function.
     bool m_bExtern;
-    //! Name of the class we derive.
+    //! Name of the class we are part of
     std::string m_MasterClass;
+    //! Token of the class we are part of
+    CBotToken m_classToken;
     CBotProgram* m_pProg;
     //! For the position of the word "extern".
     CBotToken m_extern;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/colobot.git



More information about the Pkg-games-commits mailing list