aboutsummaryrefslogtreecommitdiffstats
path: root/src/qmlcompiler/qqmljsutils.cpp
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2023-11-02 16:27:01 +0100
committerUlf Hermann <ulf.hermann@qt.io>2023-11-09 19:12:37 +0100
commitae3905531320a6603f3fe7065628853dac303cdb (patch)
treedb13ba4f3b43362f254883e215387a4496e3793b /src/qmlcompiler/qqmljsutils.cpp
parent674dc3f73d9d730e87483b86aa9d55186c57cd52 (diff)
QmlCompiler: Allow comparison of optional types
The only extra case we have to consider is the construction of an optional type from a QObject-derived since that is stored in a QVariant rather than a QObject*. Everything else we can compare is already covered by the generic QJSPrimitiveValue comparison since QJSPrimitiveValue can store undefined. Fixes: QTBUG-117799 Change-Id: Iac89f28497c34d217af156d363b8beeda76174ef Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
Diffstat (limited to 'src/qmlcompiler/qqmljsutils.cpp')
-rw-r--r--src/qmlcompiler/qqmljsutils.cpp26
1 files changed, 9 insertions, 17 deletions
diff --git a/src/qmlcompiler/qqmljsutils.cpp b/src/qmlcompiler/qqmljsutils.cpp
index 57564efee6..f5ee66b527 100644
--- a/src/qmlcompiler/qqmljsutils.cpp
+++ b/src/qmlcompiler/qqmljsutils.cpp
@@ -204,19 +204,15 @@ QQmlJSUtils::sourceDirectoryPath(const QQmlJSImporter *importer, const QString &
Utility method that checks if one of the registers is var, and the other can be
efficiently compared to it
*/
-bool canStrictlyCompareWithVar(const QQmlJSTypeResolver *typeResolver,
- const QQmlJSRegisterContent &lhsContent,
- const QQmlJSRegisterContent &rhsContent)
+bool canStrictlyCompareWithVar(
+ const QQmlJSTypeResolver *typeResolver, const QQmlJSScope::ConstPtr &lhsType,
+ const QQmlJSScope::ConstPtr &rhsType)
{
Q_ASSERT(typeResolver);
const auto varType = typeResolver->varType();
const auto nullType = typeResolver->nullType();
const auto voidType = typeResolver->voidType();
- // Use containedType() because nullptr is not a stored type.
- const auto lhsType = typeResolver->containedType(lhsContent);
- const auto rhsType = typeResolver->containedType(rhsContent);
-
return (typeResolver->equals(lhsType, varType)
&& (typeResolver->equals(rhsType, nullType) || typeResolver->equals(rhsType, voidType)))
|| (typeResolver->equals(rhsType, varType)
@@ -229,13 +225,11 @@ bool canStrictlyCompareWithVar(const QQmlJSTypeResolver *typeResolver,
Utility method that checks if one of the registers is qobject, and the other can be
efficiently compared to it
*/
-bool canCompareWithQObject(const QQmlJSTypeResolver *typeResolver,
- const QQmlJSRegisterContent &lhsContent,
- const QQmlJSRegisterContent &rhsContent)
+bool canCompareWithQObject(
+ const QQmlJSTypeResolver *typeResolver, const QQmlJSScope::ConstPtr &lhsType,
+ const QQmlJSScope::ConstPtr &rhsType)
{
Q_ASSERT(typeResolver);
- const auto lhsType = typeResolver->containedType(lhsContent);
- const auto rhsType = typeResolver->containedType(rhsContent);
return (lhsType->isReferenceType()
&& (rhsType->isReferenceType()
|| typeResolver->equals(rhsType, typeResolver->nullType())))
@@ -249,13 +243,11 @@ bool canCompareWithQObject(const QQmlJSTypeResolver *typeResolver,
Utility method that checks if both sides are QUrl type. In future, that might be extended to
support comparison with other types i.e QUrl vs string
*/
-bool canCompareWithQUrl(const QQmlJSTypeResolver *typeResolver,
- const QQmlJSRegisterContent &lhsContent,
- const QQmlJSRegisterContent &rhsContent)
+bool canCompareWithQUrl(
+ const QQmlJSTypeResolver *typeResolver, const QQmlJSScope::ConstPtr &lhsType,
+ const QQmlJSScope::ConstPtr &rhsType)
{
Q_ASSERT(typeResolver);
- const auto lhsType = typeResolver->containedType(lhsContent);
- const auto rhsType = typeResolver->containedType(rhsContent);
return typeResolver->equals(lhsType, typeResolver->urlType())
&& typeResolver->equals(rhsType, typeResolver->urlType());
}