diff --git a/src/CBot/CBotClass.cpp b/src/CBot/CBotClass.cpp index a0ec6402..b342ab42 100644 --- a/src/CBot/CBotClass.cpp +++ b/src/CBot/CBotClass.cpp @@ -639,7 +639,6 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond) { // return a method precompiled in pass 1 CBotFunction* pf = m_pMethod; - CBotFunction* prev = nullptr; CBotToken* ppp = p; CBotCStack* pStk = pStack->TokenStack(nullptr, true); CBotDefParam* params = CBotDefParam::Compile(p, pStk ); @@ -648,7 +647,6 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond) while ( pf != nullptr ) // search by name and parameters { if (pf->GetName() == pp && pf->CheckParam( params )) break; - prev = pf; pf = pf->Next(); } @@ -693,18 +691,12 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond) // compiles a method p = pBase; CBotFunction* f = - CBotFunction::Compile(p, pile, nullptr/*, false*/); + CBotFunction::Compile(p, pile, pf/*, false*/); if ( f != nullptr ) { f->m_pProg = pStack->GetProgram(); f->m_bSynchro = bSynchro; - // replaces the element in the chain - f->m_next = pf->m_next; - pf->m_next = nullptr; - delete pf; - if (prev == nullptr) m_pMethod = f; - else prev->m_next = f; } pStack->Return(nullptr, pile); } diff --git a/src/CBot/CBotInstr/CBotFunction.cpp b/src/CBot/CBotInstr/CBotFunction.cpp index 1e7e0b94..0b1e05b5 100644 --- a/src/CBot/CBotInstr/CBotFunction.cpp +++ b/src/CBot/CBotInstr/CBotFunction.cpp @@ -224,10 +224,6 @@ CBotFunction* CBotFunction::Compile(CBotToken* &p, CBotCStack* pStack, CBotFunct func->m_closeblk = (p != nullptr && p->GetPrev() != nullptr) ? *(p->GetPrev()) : CBotToken(); if ( pStk->IsOk() ) { - if ( func->m_bPublic ) // public function, return known for all - { - CBotFunction::AddPublic(func); - } return pStack->ReturnFunc(func, pStk); } } diff --git a/src/CBot/CBotProgram.cpp b/src/CBot/CBotProgram.cpp index 77dac399..c406a01a 100644 --- a/src/CBot/CBotProgram.cpp +++ b/src/CBot/CBotProgram.cpp @@ -132,6 +132,7 @@ bool CBotProgram::Compile(const std::string& program, std::vector& m_bCompileClass = false; CBotFunction::Compile(p, pStack.get(), next); if (next->IsExtern()) functions.push_back(next->GetName()/* + next->GetParams()*/); + if (next->IsPublic()) CBotFunction::AddPublic(next); next->m_pProg = this; // keeps pointers to the module next = next->Next(); } diff --git a/test/unit/CBot/CBot_test.cpp b/test/unit/CBot/CBot_test.cpp index 2a112d77..fb63ed91 100644 --- a/test/unit/CBot/CBot_test.cpp +++ b/test/unit/CBot/CBot_test.cpp @@ -1874,3 +1874,33 @@ TEST_F(CBotUT, AmbiguousCallWithNumbers) "}\n" ); } + +TEST_F(CBotUT, ClassMethodWithPublicKeyword) +{ + auto publicProgram = ExecuteTest( + "public class TestClass {\n" + " public int Test() { return 1; }\n" + "}\n" + ); + + ExecuteTest( + "int Test() { return 2; }\n" + "\n" + "extern void DontCallMethodInTestClass()\n" + "{\n" + " ASSERT(2 == Test());\n" + "}\n" + ); + + ExecuteTest( + "int Test() { return 2; }\n" + "\n" + "public class OtherClass {}\n" + "\n" + "extern void OtherClass::TestCallWithThis()\n" + "{\n" + " this.Test();\n" + "}\n", + CBotErrUndefCall + ); +}