summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/auto/qml/qmllint/data/MethodInItem.qml5
-rw-r--r--tests/auto/qml/qmllint/data/MethodInScope.qml5
-rw-r--r--tests/auto/qml/qmllint/tst_qmllint.cpp7
-rw-r--r--tools/qmllint/findunqualified.cpp1
-rw-r--r--tools/qmllint/scopetree.cpp2
5 files changed, 19 insertions, 1 deletions
diff --git a/tests/auto/qml/qmllint/data/MethodInItem.qml b/tests/auto/qml/qmllint/data/MethodInItem.qml
new file mode 100644
index 0000000000..dbdaf8bcc1
--- /dev/null
+++ b/tests/auto/qml/qmllint/data/MethodInItem.qml
@@ -0,0 +1,5 @@
+import QtQml 2.0
+
+QtObject {
+ function doThings() { console.log("things") }
+}
diff --git a/tests/auto/qml/qmllint/data/MethodInScope.qml b/tests/auto/qml/qmllint/data/MethodInScope.qml
new file mode 100644
index 0000000000..7ba0829f61
--- /dev/null
+++ b/tests/auto/qml/qmllint/data/MethodInScope.qml
@@ -0,0 +1,5 @@
+import QtQml 2.0
+
+MethodInItem {
+ Component.onCompleted: doThings()
+}
diff --git a/tests/auto/qml/qmllint/tst_qmllint.cpp b/tests/auto/qml/qmllint/tst_qmllint.cpp
index 8233dbebe5..cfcc6bf246 100644
--- a/tests/auto/qml/qmllint/tst_qmllint.cpp
+++ b/tests/auto/qml/qmllint/tst_qmllint.cpp
@@ -46,6 +46,7 @@ private Q_SLOTS:
void catchIdentifierNoFalsePositive();
void testUnmatchedSignalHandler();
void uiQml();
+ void methodInScope();
private:
QString runQmllint(const QString &fileToLint, bool shouldSucceed);
@@ -143,6 +144,12 @@ void TestQmllint::uiQml()
QVERIFY(output.isEmpty());
}
+void TestQmllint::methodInScope()
+{
+ const QString output = runQmllint("MethodInScope.qml", true);
+ QVERIFY(output.isEmpty());
+}
+
void TestQmllint::test()
{
QFETCH(QString, filename);
diff --git a/tools/qmllint/findunqualified.cpp b/tools/qmllint/findunqualified.cpp
index 42c74059c3..32eda12052 100644
--- a/tools/qmllint/findunqualified.cpp
+++ b/tools/qmllint/findunqualified.cpp
@@ -274,6 +274,7 @@ FindUnqualifiedIDVisitor::localQmlFile2FakeMetaObject(QString filePath)
auto sourceElement = static_cast<UiSourceElement *>(initMembers->member);
if (FunctionExpression *fexpr = sourceElement->sourceElement->asFunctionDefinition()) {
LanguageUtils::FakeMetaMethod method;
+ method.setMethodName(fexpr->name.toString());
method.setMethodType(LanguageUtils::FakeMetaMethod::Method);
FormalParameterList *parameters = fexpr->formals;
while (parameters) {
diff --git a/tools/qmllint/scopetree.cpp b/tools/qmllint/scopetree.cpp
index 0ba4f9e38e..1e873cca8f 100644
--- a/tools/qmllint/scopetree.cpp
+++ b/tools/qmllint/scopetree.cpp
@@ -226,7 +226,7 @@ QMap<QString, LanguageUtils::FakeMetaMethod>const &ScopeTree::methods() const
bool ScopeTree::isIdInCurrentQMlScopes(QString id) const
{
auto qmlScope = getCurrentQMLScope();
- return qmlScope->m_currentScopeQMLIdentifiers.contains(id);
+ return qmlScope->m_currentScopeQMLIdentifiers.contains(id) || qmlScope->m_methods.contains(id);
}
bool ScopeTree::isIdInCurrentJSScopes(QString id) const