diff options
author | Maximilian Goldstein <max.goldstein@qt.io> | 2022-07-06 10:15:30 +0200 |
---|---|---|
committer | Maximilian Goldstein <max.goldstein@qt.io> | 2022-07-08 10:28:50 +0200 |
commit | bd38bd435a521f5b651ce0c3a07daf88f1cab735 (patch) | |
tree | 173f57fca134d6d88a16de46fa45b770e1a81245 /src | |
parent | c29ed34de8e663e4d3200288af1bbcbaab08fe4c (diff) |
qmljscompiler: Replace categories with more specific warning ids
This change replaces a lot of generic category names with several warning
ids to replace them.
Change-Id: I9b13b931e7ed3d56b71d6292a6a77bec69647ffd
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/qmlcompiler/qqmljsimportvisitor.cpp | 47 | ||||
-rw-r--r-- | src/qmlcompiler/qqmljslinter.cpp | 8 | ||||
-rw-r--r-- | src/qmlcompiler/qqmljsliteralbindingcheck.cpp | 10 | ||||
-rw-r--r-- | src/qmlcompiler/qqmljslogger.cpp | 80 | ||||
-rw-r--r-- | src/qmlcompiler/qqmljslogger_p.h | 20 | ||||
-rw-r--r-- | src/qmlcompiler/qqmljstypepropagator.cpp | 28 | ||||
-rw-r--r-- | src/qmlcompiler/qqmljstyperesolver.cpp | 7 |
7 files changed, 131 insertions, 69 deletions
diff --git a/src/qmlcompiler/qqmljsimportvisitor.cpp b/src/qmlcompiler/qqmljsimportvisitor.cpp index 9b2ad45086..3dad4ed79d 100644 --- a/src/qmlcompiler/qqmljsimportvisitor.cpp +++ b/src/qmlcompiler/qqmljsimportvisitor.cpp @@ -171,7 +171,7 @@ bool QQmlJSImportVisitor::isTypeResolved(const QQmlJSScope::ConstPtr &type) const auto handleUnresolvedType = [this](const QQmlJSScope::ConstPtr &type) { m_logger->log(QStringLiteral("Type %1 is used but it is not resolved") .arg(getScopeName(type, type->scopeType())), - qmlType, type->sourceLocation()); + qmlUnresolvedType, type->sourceLocation()); }; return isTypeResolved(type, handleUnresolvedType); } @@ -238,11 +238,11 @@ void QQmlJSImportVisitor::resolveAliasesAndIds() if (foundProperty) { m_logger->log(QStringLiteral("Cannot deduce type of alias \"%1\"") .arg(property.propertyName()), - qmlAlias, object->sourceLocation()); + qmlMissingType, object->sourceLocation()); } else { m_logger->log(QStringLiteral("Cannot resolve alias \"%1\"") .arg(property.propertyName()), - qmlAlias, object->sourceLocation()); + qmlUnresolvedAlias, object->sourceLocation()); } } else { property.setType(type); @@ -297,7 +297,7 @@ void QQmlJSImportVisitor::resolveAliasesAndIds() continue; m_logger->log(QStringLiteral("Alias \"%1\" is part of an alias cycle") .arg(property.propertyName()), - qmlAlias, object->sourceLocation()); + qmlAliasCycle, object->sourceLocation()); } } } @@ -490,7 +490,7 @@ void QQmlJSImportVisitor::setAllBindings() if (!type->isInCustomParserParent()) { // special otherwise m_logger->log(QStringLiteral("'%1' is used but it is not resolved") .arg(getScopeName(type, type->scopeType())), - qmlType, type->sourceLocation()); + qmlUnresolvedType, type->sourceLocation()); } continue; } @@ -539,7 +539,7 @@ void QQmlJSImportVisitor::processDefaultProperties() if (!isComponent) { m_logger->log(QStringLiteral("Cannot assign to non-existent default property"), - qmlProperty, it.value().constFirst()->sourceLocation()); + qmlMissingProperty, it.value().constFirst()->sourceLocation()); } continue; @@ -550,7 +550,7 @@ void QQmlJSImportVisitor::processDefaultProperties() if (it.value().length() > 1 && !defaultProp.isList()) { m_logger->log( QStringLiteral("Cannot assign multiple objects to a default non-list property"), - qmlProperty, it.value().constFirst()->sourceLocation()); + qmlNonListProperty, it.value().constFirst()->sourceLocation()); } auto propType = defaultProp.type(); @@ -560,7 +560,7 @@ void QQmlJSImportVisitor::processDefaultProperties() "missing an import.") .arg(defaultPropertyName) .arg(defaultProp.typeName()), - qmlProperty, it.value().constFirst()->sourceLocation()); + qmlMissingProperty, it.value().constFirst()->sourceLocation()); }; if (propType.isNull()) { handleUnresolvedDefaultProperty(propType); @@ -583,7 +583,7 @@ void QQmlJSImportVisitor::processDefaultProperties() } m_logger->log(QStringLiteral("Cannot assign to default property of incompatible type"), - qmlProperty, scope->sourceLocation()); + qmlIncompatibleType, scope->sourceLocation()); } } } @@ -650,9 +650,8 @@ void QQmlJSImportVisitor::processPropertyBindingObjects() QQmlJSMetaProperty property = objectBinding.scope->property(propertyName); if (!property.isValid()) { - m_logger->log(QStringLiteral("Property \"%1\" is invalid or does not exist") - .arg(propertyName), - qmlProperty, objectBinding.location); + m_logger->log(QStringLiteral("Property \"%1\" does not exist").arg(propertyName), + qmlMissingProperty, objectBinding.location); continue; } const auto handleUnresolvedProperty = [&](const QQmlJSScope::ConstPtr &) { @@ -661,7 +660,7 @@ void QQmlJSImportVisitor::processPropertyBindingObjects() "missing an import.") .arg(propertyName) .arg(property.typeName()), - qmlProperty, objectBinding.location); + qmlUnresolvedType, objectBinding.location); }; if (property.type().isNull()) { handleUnresolvedProperty(property.type()); @@ -681,7 +680,7 @@ void QQmlJSImportVisitor::processPropertyBindingObjects() .arg(propertyName) .arg(property.typeName()) .arg(getScopeName(childScope, QQmlJSScope::QMLScope)), - qmlProperty, objectBinding.location); + qmlIncompatibleType, objectBinding.location); continue; } @@ -697,7 +696,7 @@ void QQmlJSImportVisitor::processPropertyBindingObjects() if (foundInterceptors.contains(uniqueBindingId)) { m_logger->log(QStringLiteral("Duplicate interceptor on property \"%1\"") .arg(propertyName), - qmlProperty, objectBinding.location); + qmlDuplicatePropertyBinding, objectBinding.location); } else { foundInterceptors.insert(uniqueBindingId); } @@ -705,13 +704,13 @@ void QQmlJSImportVisitor::processPropertyBindingObjects() if (foundValueSources.contains(uniqueBindingId)) { m_logger->log(QStringLiteral("Duplicate value source on property \"%1\"") .arg(propertyName), - qmlProperty, objectBinding.location); + qmlDuplicatePropertyBinding, objectBinding.location); } else if (foundObjects.contains(uniqueBindingId) || foundLiterals.contains(uniqueBindingId)) { m_logger->log(QStringLiteral("Cannot combine value source and binding on " "property \"%1\"") .arg(propertyName), - qmlProperty, objectBinding.location); + qmlDuplicatePropertyBinding, objectBinding.location); } else { foundValueSources.insert(uniqueBindingId); } @@ -719,7 +718,7 @@ void QQmlJSImportVisitor::processPropertyBindingObjects() m_logger->log(QStringLiteral("On-binding for property \"%1\" has wrong type \"%2\"") .arg(propertyName) .arg(typeName), - qmlProperty, objectBinding.location); + qmlIncompatibleType, objectBinding.location); } } else { // TODO: Warn here if binding.hasValue() is true @@ -727,7 +726,7 @@ void QQmlJSImportVisitor::processPropertyBindingObjects() m_logger->log( QStringLiteral("Cannot combine value source and binding on property \"%1\"") .arg(propertyName), - qmlProperty, objectBinding.location); + qmlDuplicatePropertyBinding, objectBinding.location); } else { foundObjects.insert(uniqueBindingId); } @@ -869,7 +868,7 @@ void QQmlJSImportVisitor::processPropertyBindings() m_logger->log(QStringLiteral("Binding assigned to \"%1\", but no property \"%1\" " "exists in the current element.") .arg(name), - qmlType, location, true, true, fixSuggestion); + qmlMissingProperty, location, true, true, fixSuggestion); continue; } @@ -879,7 +878,7 @@ void QQmlJSImportVisitor::processPropertyBindings() "to a missing import statement or incomplete " "qmltypes files.") .arg(name), - qmlType, location); + qmlMissingType, location); } const auto &annotations = property.annotations(); @@ -975,7 +974,7 @@ void QQmlJSImportVisitor::checkSignals() m_logger->log(QStringLiteral("Signal handler for \"%2\" has more formal" " parameters than the signal it handles.") .arg(pair.first), - qmlSignal, location); + qmlSignalParameters, location); continue; } @@ -991,7 +990,7 @@ void QQmlJSImportVisitor::checkSignals() .arg(i + 1) .arg(pair.first, handlerParameter) .arg(j + 1), - qmlSignal, location); + qmlSignalParameters, location); } } } @@ -1410,7 +1409,7 @@ bool QQmlJSImportVisitor::visit(UiPublicMember *publicMember) } else { m_logger->log(QStringLiteral("Invalid alias expression. Only IDs and field " "member expressions can be aliased."), - qmlAlias, expression->firstSourceLocation()); + qmlSyntax, expression->firstSourceLocation()); } } else { const QString name = buildName(publicMember->memberType); diff --git a/src/qmlcompiler/qqmljslinter.cpp b/src/qmlcompiler/qqmljslinter.cpp index 5df3b45e72..9aada37817 100644 --- a/src/qmlcompiler/qqmljslinter.cpp +++ b/src/qmlcompiler/qqmljslinter.cpp @@ -52,7 +52,7 @@ public: .arg(name) .arg(declarationLocation.startLine) .arg(declarationLocation.startColumn), - qmlType, accessLocation); + qmlVarUsedBeforeDeclaration, accessLocation); } private: @@ -274,7 +274,7 @@ void QQmlJSLinter::parseComments(QQmlJSLogger *logger, categories << category; else logger->log(u"qmllint directive on unknown category \"%1\""_s.arg(category), - qmlSyntax, loc); + qmlInvalidLintDirective, loc); } if (categories.isEmpty()) { @@ -301,8 +301,8 @@ void QQmlJSLinter::parseComments(QQmlJSLogger *logger, } else if (command == u"enable"_s) { enablesPerLine[loc.startLine + 1] |= categories; } else { - logger->log(u"Invalid qmllint directive \"%1\" provided"_s.arg(command), qmlSyntax, - loc); + logger->log(u"Invalid qmllint directive \"%1\" provided"_s.arg(command), + qmlInvalidLintDirective, loc); } } diff --git a/src/qmlcompiler/qqmljsliteralbindingcheck.cpp b/src/qmlcompiler/qqmljsliteralbindingcheck.cpp index 1be1805f6d..41eefe7592 100644 --- a/src/qmlcompiler/qqmljsliteralbindingcheck.cpp +++ b/src/qmlcompiler/qqmljsliteralbindingcheck.cpp @@ -29,8 +29,8 @@ void QQmlJSLiteralBindingCheck::run(QQmlJSImportVisitor *visitor, QQmlJSTypeReso // If the property is defined in the same scope where it is set, // we are in fact allowed to set it, even if it's not writable. if (!property.isWritable() && !scope->hasOwnProperty(propertyName)) { - logger->log(u"Cannot assign to read-only property %1"_s.arg(propertyName), qmlType, - binding.sourceLocation()); + logger->log(u"Cannot assign to read-only property %1"_s.arg(propertyName), + qmlReadOnlyProperty, binding.sourceLocation()); continue; } @@ -38,14 +38,14 @@ void QQmlJSLiteralBindingCheck::run(QQmlJSImportVisitor *visitor, QQmlJSTypeReso logger->log(u"Cannot assign binding of type %1 to %2"_s.arg( QQmlJSScope::prettyName(binding.literalTypeName()), QQmlJSScope::prettyName(property.typeName())), - qmlType, binding.sourceLocation()); + qmlIncompatibleType, binding.sourceLocation()); continue; } if (resolver->equals(property.type(), resolver->stringType()) && resolver->isNumeric(binding.literalType(resolver))) { - logger->log(u"Cannot assign a numeric constant to a string property"_s, qmlType, - binding.sourceLocation()); + logger->log(u"Cannot assign a numeric constant to a string property"_s, + qmlIncompatibleType, binding.sourceLocation()); } } } diff --git a/src/qmlcompiler/qqmljslogger.cpp b/src/qmlcompiler/qqmljslogger.cpp index da689b1b80..9bfea9b55c 100644 --- a/src/qmlcompiler/qqmljslogger.cpp +++ b/src/qmlcompiler/qqmljslogger.cpp @@ -22,15 +22,23 @@ QT_BEGIN_NAMESPACE using namespace Qt::StringLiterals; const LoggerWarningId qmlRequired { "required" }; -const LoggerWarningId qmlAlias { "alias" }; +const LoggerWarningId qmlAliasCycle { "alias-cycle" }; +const LoggerWarningId qmlUnresolvedAlias { "unresolved-alias" }; const LoggerWarningId qmlImport { "import" }; const LoggerWarningId qmlRecursionDepthErrors { "recursion-depth-errors" }; const LoggerWarningId qmlWith { "with" }; const LoggerWarningId qmlInheritanceCycle { "inheritance-cycle" }; const LoggerWarningId qmlDeprecated { "deprecated" }; -const LoggerWarningId qmlSignal { "signal" }; -const LoggerWarningId qmlType { "type" }; -const LoggerWarningId qmlProperty { "property" }; +const LoggerWarningId qmlSignalParameters { "signal-handler-parameters" }; +const LoggerWarningId qmlMissingType { "missing-type" }; +const LoggerWarningId qmlUnresolvedType { "unresolved-type" }; +const LoggerWarningId qmlRestrictedType { "restricted-type" }; +const LoggerWarningId qmlPrefixedImportType { "prefixed-import-type" }; +const LoggerWarningId qmlIncompatibleType { "incompatible-type" }; +const LoggerWarningId qmlMissingProperty { "missing-property" }; +const LoggerWarningId qmlNonListProperty { "non-list-property" }; +const LoggerWarningId qmlReadOnlyProperty { "read-only-property" }; +const LoggerWarningId qmlDuplicatePropertyBinding { "duplicate-property-binding" }; const LoggerWarningId qmlDeferredPropertyId { "deferred-property-id" }; const LoggerWarningId qmlUnqualified { "unqualified" }; const LoggerWarningId qmlUnusedImports { "unused-imports" }; @@ -42,14 +50,22 @@ const LoggerWarningId qmlCompiler { "compiler" }; const LoggerWarningId qmlControlsSanity { "controls-sanity" }; const LoggerWarningId qmlAttachedPropertyReuse { "attached-property-reuse" }; const LoggerWarningId qmlPlugin { "plugin" }; +const LoggerWarningId qmlVarUsedBeforeDeclaration { "var-used-before-declaration" }; +const LoggerWarningId qmlInvalidLintDirective { "invalid-lint-directive" }; +const LoggerWarningId qmlUseProperFunction { "use-proper-function" }; +const LoggerWarningId qmlAccessSingleton { "access-singleton-via-object" }; const QList<QQmlJSLogger::Category> &QQmlJSLogger::defaultCategories() { static const QList<QQmlJSLogger::Category> cats = { QQmlJSLogger::Category { qmlRequired.name().toString(), QStringLiteral("RequiredProperty"), QStringLiteral("Warn about required properties"), QtWarningMsg }, - QQmlJSLogger::Category { qmlAlias.name().toString(), QStringLiteral("PropertyAlias"), - QStringLiteral("Warn about alias errors"), QtWarningMsg }, + QQmlJSLogger::Category { qmlAliasCycle.name().toString(), + QStringLiteral("PropertyAliasCycles"), + QStringLiteral("Warn about alias cycles"), QtWarningMsg }, + QQmlJSLogger::Category { qmlUnresolvedAlias.name().toString(), + QStringLiteral("PropertyAliasCycles"), + QStringLiteral("Warn about unresolved aliases"), QtWarningMsg }, QQmlJSLogger::Category { qmlImport.name().toString(), QStringLiteral("ImportFailure"), QStringLiteral("Warn about failing imports and deprecated qmltypes"), @@ -69,15 +85,36 @@ const QList<QQmlJSLogger::Category> &QQmlJSLogger::defaultCategories() QQmlJSLogger::Category { qmlDeprecated.name().toString(), QStringLiteral("Deprecated"), QStringLiteral("Warn about deprecated properties and types"), QtWarningMsg }, - QQmlJSLogger::Category { qmlSignal.name().toString(), QStringLiteral("BadSignalHandler"), - QStringLiteral("Warn about bad signal handler parameters"), - QtWarningMsg }, QQmlJSLogger::Category { - qmlType.name().toString(), QStringLiteral("TypeError"), - QStringLiteral("Warn about unresolvable types and type mismatches"), QtWarningMsg }, - QQmlJSLogger::Category { qmlProperty.name().toString(), QStringLiteral("UnknownProperty"), - QStringLiteral("Warn about unknown properties"), QtWarningMsg }, - + qmlSignalParameters.name().toString(), QStringLiteral("BadSignalHandlerParameters"), + QStringLiteral("Warn about bad signal handler parameters"), QtWarningMsg }, + QQmlJSLogger::Category { qmlMissingType.name().toString(), QStringLiteral("MissingType"), + QStringLiteral("Warn about missing types"), QtWarningMsg }, + QQmlJSLogger::Category { qmlUnresolvedType.name().toString(), + QStringLiteral("UnresolvedType"), + QStringLiteral("Warn about unresolved types"), QtWarningMsg }, + QQmlJSLogger::Category { qmlRestrictedType.name().toString(), + QStringLiteral("RestrictedType"), + QStringLiteral("Warn about restricted types"), QtWarningMsg }, + QQmlJSLogger::Category { qmlPrefixedImportType.name().toString(), + QStringLiteral("PrefixedImportType"), + QStringLiteral("Warn about prefixed import types"), QtWarningMsg }, + QQmlJSLogger::Category { qmlIncompatibleType.name().toString(), + QStringLiteral("IncompatibleType"), + QStringLiteral("Warn about missing types"), QtWarningMsg }, + QQmlJSLogger::Category { qmlMissingProperty.name().toString(), + QStringLiteral("MissingProperty"), + QStringLiteral("Warn about missing properties"), QtWarningMsg }, + QQmlJSLogger::Category { qmlNonListProperty.name().toString(), + QStringLiteral("NonListProperty"), + QStringLiteral("Warn about non-list properties"), QtWarningMsg }, + QQmlJSLogger::Category { + qmlReadOnlyProperty.name().toString(), QStringLiteral("ReadOnlyProperty"), + QStringLiteral("Warn about writing to read-only properties"), QtWarningMsg }, + QQmlJSLogger::Category { qmlDuplicatePropertyBinding.name().toString(), + QStringLiteral("DuplicatePropertyBinding"), + QStringLiteral("Warn about duplicate property bindings"), + QtWarningMsg }, QQmlJSLogger::Category { qmlDeferredPropertyId.name().toString(), QStringLiteral("DeferredPropertyId"), QStringLiteral( @@ -113,7 +150,20 @@ const QList<QQmlJSLogger::Category> &QQmlJSLogger::defaultCategories() QtCriticalMsg, true }, QQmlJSLogger::Category { qmlPlugin.name().toString(), QStringLiteral("LintPluginWarnings"), QStringLiteral("Warn if a qmllint plugin finds an issue"), - QtWarningMsg, true } + QtWarningMsg, true }, + QQmlJSLogger::Category { qmlVarUsedBeforeDeclaration.name().toString(), + QStringLiteral("VarUsedBeforeDeclaration"), + QStringLiteral("Warn if a variable is used before declaration"), + QtWarningMsg }, + QQmlJSLogger::Category { + qmlInvalidLintDirective.name().toString(), QStringLiteral("InvalidLintDirective"), + QStringLiteral("Warn if an invalid qmllint comment is found"), QtWarningMsg }, + QQmlJSLogger::Category { + qmlUseProperFunction.name().toString(), QStringLiteral("UseProperFunction"), + QStringLiteral("Warn if var is used for storing functions"), QtWarningMsg }, + QQmlJSLogger::Category { + qmlAccessSingleton.name().toString(), QStringLiteral("AccessSingletonViaObject"), + QStringLiteral("Warn if a singleton is accessed via an object"), QtWarningMsg } }; return cats; diff --git a/src/qmlcompiler/qqmljslogger_p.h b/src/qmlcompiler/qqmljslogger_p.h index 7f894d9f35..f6414b0b88 100644 --- a/src/qmlcompiler/qqmljslogger_p.h +++ b/src/qmlcompiler/qqmljslogger_p.h @@ -96,15 +96,23 @@ private: }; extern const Q_QMLCOMPILER_PRIVATE_EXPORT LoggerWarningId qmlRequired; -extern const Q_QMLCOMPILER_PRIVATE_EXPORT LoggerWarningId qmlAlias; +extern const Q_QMLCOMPILER_PRIVATE_EXPORT LoggerWarningId qmlUnresolvedAlias; +extern const Q_QMLCOMPILER_PRIVATE_EXPORT LoggerWarningId qmlAliasCycle; extern const Q_QMLCOMPILER_PRIVATE_EXPORT LoggerWarningId qmlImport; extern const Q_QMLCOMPILER_PRIVATE_EXPORT LoggerWarningId qmlRecursionDepthErrors; extern const Q_QMLCOMPILER_PRIVATE_EXPORT LoggerWarningId qmlWith; extern const Q_QMLCOMPILER_PRIVATE_EXPORT LoggerWarningId qmlInheritanceCycle; extern const Q_QMLCOMPILER_PRIVATE_EXPORT LoggerWarningId qmlDeprecated; -extern const Q_QMLCOMPILER_PRIVATE_EXPORT LoggerWarningId qmlSignal; -extern const Q_QMLCOMPILER_PRIVATE_EXPORT LoggerWarningId qmlType; -extern const Q_QMLCOMPILER_PRIVATE_EXPORT LoggerWarningId qmlProperty; +extern const Q_QMLCOMPILER_PRIVATE_EXPORT LoggerWarningId qmlSignalParameters; +extern const Q_QMLCOMPILER_PRIVATE_EXPORT LoggerWarningId qmlMissingType; +extern const Q_QMLCOMPILER_PRIVATE_EXPORT LoggerWarningId qmlUnresolvedType; +extern const Q_QMLCOMPILER_PRIVATE_EXPORT LoggerWarningId qmlIncompatibleType; +extern const Q_QMLCOMPILER_PRIVATE_EXPORT LoggerWarningId qmlMissingProperty; +extern const Q_QMLCOMPILER_PRIVATE_EXPORT LoggerWarningId qmlRestrictedType; +extern const Q_QMLCOMPILER_PRIVATE_EXPORT LoggerWarningId qmlPrefixedImportType; +extern const Q_QMLCOMPILER_PRIVATE_EXPORT LoggerWarningId qmlNonListProperty; +extern const Q_QMLCOMPILER_PRIVATE_EXPORT LoggerWarningId qmlReadOnlyProperty; +extern const Q_QMLCOMPILER_PRIVATE_EXPORT LoggerWarningId qmlDuplicatePropertyBinding; extern const Q_QMLCOMPILER_PRIVATE_EXPORT LoggerWarningId qmlDeferredPropertyId; extern const Q_QMLCOMPILER_PRIVATE_EXPORT LoggerWarningId qmlUnqualified; extern const Q_QMLCOMPILER_PRIVATE_EXPORT LoggerWarningId qmlUnusedImports; @@ -116,6 +124,10 @@ extern const Q_QMLCOMPILER_PRIVATE_EXPORT LoggerWarningId qmlCompiler; extern const Q_QMLCOMPILER_PRIVATE_EXPORT LoggerWarningId qmlControlsSanity; extern const Q_QMLCOMPILER_PRIVATE_EXPORT LoggerWarningId qmlAttachedPropertyReuse; extern const Q_QMLCOMPILER_PRIVATE_EXPORT LoggerWarningId qmlPlugin; +extern const Q_QMLCOMPILER_PRIVATE_EXPORT LoggerWarningId qmlVarUsedBeforeDeclaration; +extern const Q_QMLCOMPILER_PRIVATE_EXPORT LoggerWarningId qmlInvalidLintDirective; +extern const Q_QMLCOMPILER_PRIVATE_EXPORT LoggerWarningId qmlUseProperFunction; +extern const Q_QMLCOMPILER_PRIVATE_EXPORT LoggerWarningId qmlAccessSingleton; struct Message : public QQmlJS::DiagnosticMessage { diff --git a/src/qmlcompiler/qqmljstypepropagator.cpp b/src/qmlcompiler/qqmljstypepropagator.cpp index 94a91ccd9b..1950e33d92 100644 --- a/src/qmlcompiler/qqmljstypepropagator.cpp +++ b/src/qmlcompiler/qqmljstypepropagator.cpp @@ -94,7 +94,7 @@ void QQmlJSTypePropagator::generate_Ret() m_logger->log(u"Cannot assign binding of type %1 to %2"_s.arg( m_typeResolver->containedTypeName(m_state.accumulatorIn(), true), m_typeResolver->containedTypeName(m_returnType, true)), - qmlType, getCurrentBindingSourceLocation()); + qmlIncompatibleType, getCurrentBindingSourceLocation()); return; } @@ -475,7 +475,7 @@ bool QQmlJSTypePropagator::isRestricted(const QString &propertyName) const if (!restrictedKind.isEmpty()) m_logger->log(u"Type is %1. You cannot access \"%2\" from here."_s.arg(restrictedKind, propertyName), - qmlType, getCurrentSourceLocation()); + qmlRestrictedType, getCurrentSourceLocation()); return !restrictedKind.isEmpty(); } @@ -499,7 +499,7 @@ bool QQmlJSTypePropagator::isMissingPropertyType(QQmlJSScope::ConstPtr scope, m_logger->log( u"Type \"%1\" of property \"%2\" not %3. This is likely due to a missing dependency entry or a type not being exposed declaratively."_s .arg(property.typeName(), propertyName, errorType), - qmlType, getCurrentSourceLocation()); + qmlUnresolvedType, getCurrentSourceLocation()); return true; } @@ -538,7 +538,7 @@ bool QQmlJSTypePropagator::isCallingProperty(QQmlJSScope::ConstPtr scope, const errorType = u"not a method"_s; } - m_logger->log(u"%1 \"%2\" is %3"_s.arg(propertyType, name, errorType), qmlType, + m_logger->log(u"%1 \"%2\" is %3"_s.arg(propertyType, name, errorType), qmlUseProperFunction, getCurrentSourceLocation(), true, true, {}); return true; @@ -598,7 +598,7 @@ void QQmlJSTypePropagator::generate_StoreNameSloppy(int nameIndex) if (!type.isWritable() && !m_function->qmlScope->hasOwnProperty(name)) { setError(u"Can't assign to read-only property %1"_s.arg(name)); - m_logger->log(u"Cannot assign to read-only property %1"_s.arg(name), qmlProperty, + m_logger->log(u"Cannot assign to read-only property %1"_s.arg(name), qmlReadOnlyProperty, getCurrentSourceLocation()); return; @@ -749,11 +749,13 @@ void QQmlJSTypePropagator::propagatePropertyLookup(const QString &propertyName) return; } if (m_state.accumulatorIn().isImportNamespace()) - m_logger->log(u"Type not found in namespace"_s, qmlType, getCurrentSourceLocation()); + m_logger->log(u"Type not found in namespace"_s, qmlUnresolvedType, + getCurrentSourceLocation()); } else if (m_state.accumulatorOut().variant() == QQmlJSRegisterContent::Singleton && m_state.accumulatorIn().variant() == QQmlJSRegisterContent::ObjectModulePrefix) { - m_logger->log(u"Cannot load singleton as property of object"_s, qmlType, - getCurrentSourceLocation()); + m_logger->log( + u"Cannot access singleton as a property of an object. Did you want to access an attached object?"_s, + qmlAccessSingleton, getCurrentSourceLocation()); setAccumulator(QQmlJSRegisterContent()); } @@ -802,7 +804,7 @@ void QQmlJSTypePropagator::propagatePropertyLookup(const QString &propertyName) } m_logger->log(u"Property \"%1\" not found on type \"%2\""_s.arg(propertyName).arg(typeName), - qmlType, getCurrentSourceLocation(), true, true, fixSuggestion); + qmlMissingProperty, getCurrentSourceLocation(), true, true, fixSuggestion); return; } @@ -822,7 +824,7 @@ void QQmlJSTypePropagator::propagatePropertyLookup(const QString &propertyName) if (!m_state.accumulatorOut().property().type()) { m_logger->log( QString::fromLatin1("Type of property \"%2\" not found").arg(propertyName), - qmlType, getCurrentSourceLocation()); + qmlMissingType, getCurrentSourceLocation()); } } @@ -892,8 +894,8 @@ void QQmlJSTypePropagator::generate_StoreProperty(int nameIndex, int base) if (!property.isWritable()) { setError(u"Can't assign to read-only property %1"_s.arg(propertyName)); - m_logger->log(u"Cannot assign to read-only property %1"_s.arg(propertyName), qmlProperty, - getCurrentSourceLocation()); + m_logger->log(u"Cannot assign to read-only property %1"_s.arg(propertyName), + qmlReadOnlyProperty, getCurrentSourceLocation()); return; } @@ -1026,7 +1028,7 @@ void QQmlJSTypePropagator::generate_CallProperty(int nameIndex, int base, int ar m_logger->log(u"Property \"%1\" not found on type \"%2\""_s.arg( propertyName, m_typeResolver->containedTypeName(callBase, true)), - qmlType, getCurrentSourceLocation(), true, true, fixSuggestion); + qmlMissingProperty, getCurrentSourceLocation(), true, true, fixSuggestion); return; } diff --git a/src/qmlcompiler/qqmljstyperesolver.cpp b/src/qmlcompiler/qqmljstyperesolver.cpp index 1c8feadaee..64a02a66da 100644 --- a/src/qmlcompiler/qqmljstyperesolver.cpp +++ b/src/qmlcompiler/qqmljstyperesolver.cpp @@ -1118,10 +1118,9 @@ QQmlJSRegisterContent QQmlJSTypeResolver::memberType(const QQmlJSRegisterContent } if (type.isImportNamespace()) { if (type.scopeType()->accessSemantics() != QQmlJSScope::AccessSemantics::Reference) { - m_logger->log( - u"Cannot use non-reference type %1 as base of namespaced attached type"_s.arg( - type.scopeType()->internalName()), - qmlType, type.scopeType()->sourceLocation()); + m_logger->log(u"Cannot use a non-QObject type %1 to access prefixed import"_s.arg( + type.scopeType()->internalName()), + qmlPrefixedImportType, type.scopeType()->sourceLocation()); return {}; } |