Commit 7db3b660 authored by Przemyslaw Gorszkowski's avatar Przemyslaw Gorszkowski Committed by Nikolai Kosjar
Browse files

C++ editor: Highlight member variable



Highlight member variable when there is also
enum value with the same name

Task-number: QTCREATORBUG-7525
Change-Id: I0990844a20fdf9e87a807fde10708344b9c3497b
Reviewed-by: Orgad Shaneh's avatarOrgad Shaneh <orgads@gmail.com>
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@digia.com>
parent f1cec462
......@@ -787,7 +787,11 @@ void CheckSymbols::checkName(NameAST *ast, Scope *scope)
}
}
} else if (maybeType(ast->name) || maybeStatic(ast->name)) {
maybeAddTypeOrStatic(_context.lookup(ast->name, scope), ast);
if (! maybeAddTypeOrStatic(_context.lookup(ast->name, scope), ast)) {
// it can be a local variable
if (maybeField(ast->name))
maybeAddField(_context.lookup(ast->name, scope), ast);
}
} else if (maybeField(ast->name)) {
maybeAddField(_context.lookup(ast->name, scope), ast);
}
......
......@@ -183,6 +183,7 @@ private slots:
void test_checksymbols_FunctionUse();
void test_checksymbols_PseudoKeywordUse();
void test_checksymbols_StaticUse();
void test_checksymbols_VariableHasTheSameNameAsEnumUse();
};
void tst_CheckSymbols::test_checksymbols_TypeUse()
......@@ -377,5 +378,35 @@ void tst_CheckSymbols::test_checksymbols_StaticUse()
TestData::check(source, expectedUses);
}
void tst_CheckSymbols::test_checksymbols_VariableHasTheSameNameAsEnumUse()
{
const QByteArray source =
"struct Foo\n"
"{\n"
" enum E { bar, baz };\n"
"};\n"
"\n"
"struct Boo\n"
"{\n"
" int foo;\n"
" int bar;\n"
" int baz;\n"
"};\n"
;
const QList<Use> expectedUses = QList<Use>()
<< Use(1, 8, 3, SemanticInfo::TypeUse)
<< Use(3, 19, 3, SemanticInfo::EnumerationUse)
<< Use(3, 14, 3, SemanticInfo::EnumerationUse)
<< Use(3, 10, 1, SemanticInfo::TypeUse)
<< Use(6, 8, 3, SemanticInfo::TypeUse)
<< Use(8, 9, 3, SemanticInfo::FieldUse)
<< Use(9, 9, 3, SemanticInfo::FieldUse)
<< Use(10, 9, 3, SemanticInfo::FieldUse)
;
TestData::check(source, expectedUses);
}
QTEST_APPLESS_MAIN(tst_CheckSymbols)
#include "tst_checksymbols.moc"
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