diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2023-01-04 14:35:17 +0100 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2023-01-26 11:42:34 +0100 |
commit | 59d6cf324dfb80febf65dd735990b4e9e3a7e54b (patch) | |
tree | f526786ff4d00410e1035eba9a3382ab095042a1 /src | |
parent | 0c5821b366ce32472a91c8907432e37e8618847f (diff) |
qmllint: Do not warn when accessing properties of global constructors
We are treating global constructor functions as methods. But while they
are callable, they also have properties that can be accessed.
Accessing those should not trigger any warning. However, prior to this
commit, any property access to a method would yield a warning.
As we don't store the list of known properties in the
jsroot.qmltypes, we cannot really validate them. Moreover, it is also
possilbe to extend the prototypes, so it might never be feasible to
generate warnings.
Thus, for now simply don't create warnings for JS globals in
QQmlJSTypePropagator::isRestricted.
Fixes: QTBUG-109204
Pick-to: 6.5 6.4
Change-Id: I992365ea716827a562886d7204b2401062772f9a
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/qmlcompiler/qqmljstypepropagator.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/qmlcompiler/qqmljstypepropagator.cpp b/src/qmlcompiler/qqmljstypepropagator.cpp index 4e8f598b32..153e93fdbc 100644 --- a/src/qmlcompiler/qqmljstypepropagator.cpp +++ b/src/qmlcompiler/qqmljstypepropagator.cpp @@ -487,6 +487,22 @@ bool QQmlJSTypePropagator::isRestricted(const QString &propertyName) const restrictedKind = u"an unscoped enum"_s; } } else if (accumulatorIn.value().content.isMethod()) { + auto overloadSet = accumulatorIn.value().content.method(); + auto potentiallyJSMethod = std::any_of( + overloadSet.cbegin(), overloadSet.cend(), + [](const QQmlJSMetaMethod &overload){ + return overload.isJavaScriptFunction(); + }); + if (potentiallyJSMethod) { + /* JS global constructors like Number get detected as methods + However, they still have properties that can be accessed + e.g. Number.EPSILON. This also isn't restricted to constructor + functions, so use isJavaScriptFunction as an overapproximation. + That catches also QQmlV4Function, but we're purging uses of it + anyway. + */ + return false; + } restrictedKind = u"a method"_s; } |