From 65b2edbd82dffe5ea13dbce299baa80109cfdf1f Mon Sep 17 00:00:00 2001 From: Marco Benelli Date: Tue, 22 Aug 2017 17:24:54 +0200 Subject: [PATCH] qmljs: better handling of attached properties Attached properties used to cause false positives in the highlighter, because when using qualified ids, only the first part was checked as candidate for being at attached property. Task-number: QTCREATORBUG-18707 Change-Id: I6b1b569bc1766325decbc5d100c16a4e0dc3634f Reviewed-by: Thomas Hartmann --- src/libs/qmljs/qmljscheck.cpp | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/libs/qmljs/qmljscheck.cpp b/src/libs/qmljs/qmljscheck.cpp index 52180c4cc3a..6bc596eacde 100644 --- a/src/libs/qmljs/qmljscheck.cpp +++ b/src/libs/qmljs/qmljscheck.cpp @@ -1709,6 +1709,7 @@ bool Check::visit(TypeOfExpression *ast) /// ### Maybe put this into the context as a helper function. const Value *Check::checkScopeObjectMember(const UiQualifiedId *id) { + if (!_importsOk) return 0; @@ -1716,6 +1717,17 @@ const Value *Check::checkScopeObjectMember(const UiQualifiedId *id) if (scopeObjects.isEmpty()) return 0; + const auto getAttachedTypes = [this, &scopeObjects](const QString &propertyName) { + bool isAttachedProperty = false; + if (! propertyName.isEmpty() && propertyName[0].isUpper()) { + isAttachedProperty = true; + if (const ObjectValue *qmlTypes = _scopeChain.qmlTypes()) + scopeObjects += qmlTypes; + } + return isAttachedProperty; + }; + + if (! id) return 0; // ### error? @@ -1728,12 +1740,7 @@ const Value *Check::checkScopeObjectMember(const UiQualifiedId *id) return 0; // ### should probably be a special value // attached properties - bool isAttachedProperty = false; - if (! propertyName.isEmpty() && propertyName[0].isUpper()) { - isAttachedProperty = true; - if (const ObjectValue *qmlTypes = _scopeChain.qmlTypes()) - scopeObjects += qmlTypes; - } + bool isAttachedProperty = getAttachedTypes(propertyName); if (scopeObjects.isEmpty()) return 0; @@ -1775,6 +1782,9 @@ const Value *Check::checkScopeObjectMember(const UiQualifiedId *id) idPart = idPart->next; propertyName = idPart->name.toString(); + isAttachedProperty = getAttachedTypes(propertyName); + if (isAttachedProperty) + return 0; value = objectValue->lookupMember(propertyName, _context); if (! value) {