From ffca73c79d7733f06416f211d5d544dd037c9532 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Wed, 18 Oct 2017 15:50:32 +0200 Subject: Tell QQmlImportInstance::resolveType what kind of type we want In QQmlTypeData::resolveTypes() we know if we're looking at a reference to a composite singleton type, or some other type reference. When we call resolveType() we expect the correct type to be returned, not only based on URL, but also based on its singleton property. QQmlTypeData::resolveType() eventually invokes QQmlImportInstance::resolveType() which will call fetchOrCreateTypeForUrl(), passing a parameter on whether the result should be a composite singleton. When operating on a qmldir component the component itself encodes this. When fetching a type from a local file without qmldir, we currently assume that it isn't a singleton, no matter QQmlTypeData::resolveTypes() has determined. This means that actual singletons loaded this way later get refused by the sanity check. In order to fix this, pass the information about the expected singleton property on to QQmlImportInstance. This is done using QQmlType::RegistrationType, which gets another entry for "any type". If the expected type is CompositeSingletonType QQmlTypeData::resolveType() will not create a non-singleton type. If it is any specific other type, it will not create a composite singleton. And if it is AnyRegistrationType, it will behave as it previously did. Change-Id: I6b7e082b63582e0aed946bb3d19077b94c7a45f7 Reviewed-by: Lars Knoll --- src/qml/qml/qqmltypeloader.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'src/qml/qml/qqmltypeloader.cpp') diff --git a/src/qml/qml/qqmltypeloader.cpp b/src/qml/qml/qqmltypeloader.cpp index 342e6c0725..193acb04be 100644 --- a/src/qml/qml/qqmltypeloader.cpp +++ b/src/qml/qml/qqmltypeloader.cpp @@ -2612,7 +2612,8 @@ void QQmlTypeData::resolveTypes() int majorVersion = csRef.majorVersion > -1 ? csRef.majorVersion : -1; int minorVersion = csRef.minorVersion > -1 ? csRef.minorVersion : -1; - if (!resolveType(typeName, majorVersion, minorVersion, ref)) + if (!resolveType(typeName, majorVersion, minorVersion, ref, -1, -1, true, + QQmlType::CompositeSingletonType)) return; if (ref.type.isCompositeSingleton()) { @@ -2640,7 +2641,9 @@ void QQmlTypeData::resolveTypes() const QString name = stringAt(unresolvedRef.key()); - if (!resolveType(name, majorVersion, minorVersion, ref, unresolvedRef->location.line, unresolvedRef->location.column, reportErrors) && reportErrors) + if (!resolveType(name, majorVersion, minorVersion, ref, unresolvedRef->location.line, + unresolvedRef->location.column, reportErrors, + QQmlType::AnyRegistrationType) && reportErrors) return; if (ref.type.isComposite()) { @@ -2710,20 +2713,22 @@ QQmlCompileError QQmlTypeData::buildTypeResolutionCaches( return noError; } -bool QQmlTypeData::resolveType(const QString &typeName, int &majorVersion, int &minorVersion, TypeReference &ref, int lineNumber, int columnNumber, bool reportErrors) +bool QQmlTypeData::resolveType(const QString &typeName, int &majorVersion, int &minorVersion, + TypeReference &ref, int lineNumber, int columnNumber, + bool reportErrors, QQmlType::RegistrationType registrationType) { QQmlImportNamespace *typeNamespace = 0; QList errors; - bool typeFound = m_importCache.resolveType(typeName, &ref.type, - &majorVersion, &minorVersion, &typeNamespace, &errors); + bool typeFound = m_importCache.resolveType(typeName, &ref.type, &majorVersion, &minorVersion, + &typeNamespace, &errors, registrationType); if (!typeNamespace && !typeFound && !m_implicitImportLoaded) { // Lazy loading of implicit import if (loadImplicitImport()) { // Try again to find the type errors.clear(); - typeFound = m_importCache.resolveType(typeName, &ref.type, - &majorVersion, &minorVersion, &typeNamespace, &errors); + typeFound = m_importCache.resolveType(typeName, &ref.type, &majorVersion, &minorVersion, + &typeNamespace, &errors, registrationType); } else { return false; //loadImplicitImport() hit an error, and called setError already } -- cgit v1.2.3