Commit cab6ed5e authored by Erik Verbruggen's avatar Erik Verbruggen Committed by Eike Ziller
Browse files

Fix: no scope walking for name resolving after MemAccess operator



Change-Id: Ic093079fa65d8d749911fd9f5b0f629e9fe68a1e
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@digia.com>

Conflicts:
	tests/auto/cplusplus/findusages/tst_findusages.cpp

Change-Id: I87d305e2d68582aa00b92f9599368615cd76ec74
Reviewed-by: default avatarEike Ziller <eike.ziller@digia.com>
parent 56966f37
......@@ -145,6 +145,7 @@ private:
AlreadyConsideredClassContainer<TemplateNameId> _alreadyConsideredTemplates;
#ifdef DEBUG_LOOKUP
public:
const Name *_name;
#endif // DEBUG_LOOKUP
......
......@@ -806,7 +806,7 @@ bool ResolveExpression::visit(MemberAccessAST *ast)
const int accessOp = tokenKind(ast->access_token);
if (ClassOrNamespace *binding = baseExpression(baseResults, accessOp))
addResults(binding->lookup(memberName));
addResults(binding->find(memberName));
return false;
}
......
......@@ -997,7 +997,6 @@ void CppToolsPlugin::test_completion_cyclic_inheritance_data()
"};\n"
"\n"
"Class<int> c;\n"
"c.\n"
"@\n"
;
completions.append("Class");
......@@ -1007,5 +1006,4 @@ void CppToolsPlugin::test_completion_cyclic_inheritance_data()
completions.append("class_recurse_t");
QTest::newRow("case: direct cyclic inheritance with templates, more complex situation")
<< code << completions;
}
......@@ -77,6 +77,8 @@ class tst_FindUsages: public QObject
private Q_SLOTS:
void inlineMethod();
void shadowedNames_1();
void shadowedNames_2();
// Qt keywords
void qproperty_1();
......@@ -123,6 +125,69 @@ void tst_FindUsages::inlineMethod()
QCOMPARE(findUsages.references().size(), 2);
}
void tst_FindUsages::shadowedNames_1()
{
const QByteArray src = "\n"
"int a();\n"
"struct X{ int a(); };\n"
"int X::a() {}\n"
"void f(X x) { x.a(); }\n"
"void g() { a(); }\n"
;
Document::Ptr doc = Document::create("shadowedNames_1");
doc->setUtf8Source(src);
doc->parse();
doc->check();
QVERIFY(doc->diagnosticMessages().isEmpty());
QCOMPARE(doc->globalSymbolCount(), 5U);
Snapshot snapshot;
snapshot.insert(doc);
Declaration *d = doc->globalSymbolAt(0)->asDeclaration();
QVERIFY(d);
QCOMPARE(d->name()->identifier()->chars(), "a");
FindUsages findUsages(src, doc, snapshot);
findUsages(d);
QCOMPARE(findUsages.usages().size(), 2);
}
void tst_FindUsages::shadowedNames_2()
{
const QByteArray src = "\n"
"int a();\n"
"struct X{ int a(); };\n"
"int X::a() {}\n"
"void f(X x) { x.a(); }\n"
"void g() { a(); }\n";
Document::Ptr doc = Document::create("shadowedNames_2");
doc->setUtf8Source(src);
doc->parse();
doc->check();
QVERIFY(doc->diagnosticMessages().isEmpty());
QCOMPARE(doc->globalSymbolCount(), 5U);
Snapshot snapshot;
snapshot.insert(doc);
Class *c = doc->globalSymbolAt(1)->asClass();
QVERIFY(c);
QCOMPARE(c->name()->identifier()->chars(), "X");
QCOMPARE(c->memberCount(), 1U);
Declaration *d = c->memberAt(0)->asDeclaration();
QVERIFY(d);
QCOMPARE(d->name()->identifier()->chars(), "a");
FindUsages findUsages(src, doc, snapshot);
findUsages(d);
QCOMPARE(findUsages.usages().size(), 3);
}
#if 0
@interface Clazz {} +(void)method:(int)arg; @end
@implementation Clazz +(void)method:(int)arg {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment