Fix finding in-class methods when searching by ID
parent
4a14a44f3f
commit
3debfb9182
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -132,6 +132,7 @@ bool CBotProgram::Compile(const std::string& program, std::vector<std::string>&
|
|||
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();
|
||||
}
|
||||
|
|
|
@ -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
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue