forked from qt-creator/qt-creator
Fix: no scope walking for name resolving after MemAccess operator
Change-Id: Ic093079fa65d8d749911fd9f5b0f629e9fe68a1e Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
This commit is contained in:
@@ -111,6 +111,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;
|
||||
}
|
||||
|
||||
@@ -996,7 +996,6 @@ void CppToolsPlugin::test_completion_cyclic_inheritance_data()
|
||||
"};\n"
|
||||
"\n"
|
||||
"Class<int> c;\n"
|
||||
"c.\n"
|
||||
"@\n"
|
||||
;
|
||||
completions.append("Class");
|
||||
@@ -1006,7 +1005,6 @@ 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;
|
||||
|
||||
}
|
||||
|
||||
void CppToolsPlugin::test_completion_enclosing_template_class()
|
||||
|
||||
@@ -79,6 +79,8 @@ private Q_SLOTS:
|
||||
void inlineMethod();
|
||||
void lambdaCaptureByValue();
|
||||
void lambdaCaptureByReference();
|
||||
void shadowedNames_1();
|
||||
void shadowedNames_2();
|
||||
|
||||
// Qt keywords
|
||||
void qproperty_1();
|
||||
@@ -189,6 +191,69 @@ void tst_FindUsages::lambdaCaptureByReference()
|
||||
QCOMPARE(findUsages.usages().size(), 3);
|
||||
}
|
||||
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user