Skip to content

Commit 7b106c0

Browse files
committed
Fixed #8603 (SymbolDatabase: 2 scopes with same function)
1 parent df9b243 commit 7b106c0

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

lib/symboldatabase.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2046,7 +2046,10 @@ Function* SymbolDatabase::addGlobalFunction(Scope*& scope, const Token*& tok, co
20462046
{
20472047
Function* function = nullptr;
20482048
for (std::multimap<std::string, const Function *>::iterator i = scope->functionMap.find(tok->str()); i != scope->functionMap.end() && i->first == tok->str(); ++i) {
2049-
if (Function::argsMatch(scope, i->second->argDef->next(), argStart->next(), emptyString, 0)) {
2049+
const Function *f = i->second;
2050+
if (f->hasBody())
2051+
continue;
2052+
if (Function::argsMatch(scope, f->argDef->next(), argStart->next(), emptyString, 0)) {
20502053
function = const_cast<Function *>(i->second);
20512054
break;
20522055
}

test/testsymboldatabase.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ class TestSymbolDatabase: public TestFixture {
290290
TEST_CASE(symboldatabase70);
291291
TEST_CASE(symboldatabase71);
292292
TEST_CASE(symboldatabase72); // #8600
293+
TEST_CASE(symboldatabase73); // #8603
293294

294295
TEST_CASE(enum1);
295296
TEST_CASE(enum2);
@@ -3941,6 +3942,26 @@ class TestSymbolDatabase: public TestFixture {
39413942
ASSERT(f && f->function() && f->function()->type == Function::eCopyConstructor);
39423943
}
39433944

3945+
void symboldatabase73() { // #8603
3946+
GET_SYMBOL_DB("namespace swizzle {\n"
3947+
" template <comp> void swizzle(tvec2<f16>) {}\n"
3948+
" template <comp x, comp y> void swizzle(tvec2<f16> v) {}\n"
3949+
"}");
3950+
3951+
ASSERT_EQUALS(4, db->scopeList.size());
3952+
ASSERT_EQUALS(2, db->functionScopes.size());
3953+
3954+
const Scope *f1 = db->functionScopes[0];
3955+
ASSERT_EQUALS(2, f1->bodyStart->linenr());
3956+
ASSERT_EQUALS(2, f1->bodyEnd->linenr());
3957+
ASSERT_EQUALS(2, f1->function->token->linenr());
3958+
3959+
const Scope *f2 = db->functionScopes[1];
3960+
ASSERT_EQUALS(3, f2->bodyStart->linenr());
3961+
ASSERT_EQUALS(3, f2->bodyEnd->linenr());
3962+
ASSERT_EQUALS(3, f2->function->token->linenr());
3963+
}
3964+
39443965
void enum1() {
39453966
GET_SYMBOL_DB("enum BOOL { FALSE, TRUE }; enum BOOL b;");
39463967

0 commit comments

Comments
 (0)