diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-10-27 09:56:41 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-10-29 07:37:53 +0200 |
commit | ecbe9eb420461390585ac7645299c285bbc3e5b6 (patch) | |
tree | 0da6737efd1243850a4edcaffecc528e0eeab371 /sources | |
parent | c0c552e72d7fb851649ffd89b5eb8671a30e1b9b (diff) |
shiboken6: Do not crash when class cannot be found in the overload sorter
Print an error message instead.
As a drive-by, add a helper to create a class-qualified signature
for error reporting purposes to AbstractMetaFunction.
Task-number: PYSIDE-1684
Change-Id: I8417f405b4ce1b64060aad0696e5d328869cb83e
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
(cherry picked from commit 1e7f97e082d5430ff8323bc58c480d00a4f64852)
Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources')
6 files changed, 33 insertions, 9 deletions
diff --git a/sources/shiboken6/ApiExtractor/abstractmetafunction.cpp b/sources/shiboken6/ApiExtractor/abstractmetafunction.cpp index f1bcc3bbb..fc79a8c2a 100644 --- a/sources/shiboken6/ApiExtractor/abstractmetafunction.cpp +++ b/sources/shiboken6/ApiExtractor/abstractmetafunction.cpp @@ -505,6 +505,15 @@ QString AbstractMetaFunction::signature() const return d->signature(); } +QString AbstractMetaFunction::classQualifiedSignature() const +{ + QString result; + if (d->m_implementingClass) + result += d->m_implementingClass->qualifiedCppName() + u"::"_qs; + result += signature(); + return result; +} + bool AbstractMetaFunction::isConstant() const { return d->m_constant; diff --git a/sources/shiboken6/ApiExtractor/abstractmetafunction.h b/sources/shiboken6/ApiExtractor/abstractmetafunction.h index 9001c16e5..1682b0493 100644 --- a/sources/shiboken6/ApiExtractor/abstractmetafunction.h +++ b/sources/shiboken6/ApiExtractor/abstractmetafunction.h @@ -284,6 +284,8 @@ public: QStringList introspectionCompatibleSignatures(const QStringList &resolvedArguments = QStringList()) const; QString signature() const; + /// Return a signature qualified by class name, for error reporting. + QString classQualifiedSignature() const; bool isConstant() const; void setConstant(bool constant); diff --git a/sources/shiboken6/ApiExtractor/messages.cpp b/sources/shiboken6/ApiExtractor/messages.cpp index 00d9dd816..ffca9bcd8 100644 --- a/sources/shiboken6/ApiExtractor/messages.cpp +++ b/sources/shiboken6/ApiExtractor/messages.cpp @@ -272,9 +272,8 @@ QString msgShadowingFunction(const AbstractMetaFunction *f1, auto f2Class = f2->implementingClass(); QString result; QTextStream str(&result); - str << f2Class->sourceLocation() << "Shadowing: " << f1->implementingClass()->name() - << "::" << f1->signature() << " and " << f2Class->name() << "::" - << f2->signature(); + str << f2Class->sourceLocation() << "Shadowing: " << f1->classQualifiedSignature() + << " and " << f2->classQualifiedSignature(); return result; } @@ -832,3 +831,12 @@ QString msgInvalidTargetLanguageApiName(const QString &name) return u"Invalid target language API name \""_qs + name + u"\"."_qs; } + +QString msgArgumentClassNotFound(const AbstractMetaFunctionCPtr &func, + const TypeEntry *t) +{ + QString result; + QTextStream(&result) << "Internal Error: Class \"" << t->qualifiedCppName() + << "\" for \"" << func->classQualifiedSignature() << "\" not found!"; + return result; +} diff --git a/sources/shiboken6/ApiExtractor/messages.h b/sources/shiboken6/ApiExtractor/messages.h index 7e6fd87a5..c0127f83e 100644 --- a/sources/shiboken6/ApiExtractor/messages.h +++ b/sources/shiboken6/ApiExtractor/messages.h @@ -239,4 +239,7 @@ QString msgDuplicateBuiltInTypeEntry(const QString &name); QString msgDuplicateTypeEntry(const QString &name); QString msgInvalidTargetLanguageApiName(const QString &name); +QString msgArgumentClassNotFound(const AbstractMetaFunctionCPtr &func, + const TypeEntry *t); + #endif // MESSAGES_H diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.cpp b/sources/shiboken6/generator/shiboken/cppgenerator.cpp index cc77dc799..47bc3d832 100644 --- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp +++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp @@ -996,10 +996,8 @@ QString CppGenerator::virtualMethodReturn(TextStream &s, const ApiExtractorResul QString errorMessage; const auto defaultReturnExpr = minimalConstructor(api, returnType, &errorMessage); if (!defaultReturnExpr.has_value()) { - QString errorMsg = QLatin1String(__FUNCTION__) + QLatin1String(": "); - if (const AbstractMetaClass *c = func->implementingClass()) - errorMsg += c->qualifiedCppName() + QLatin1String("::"); - errorMsg += func->signature(); + QString errorMsg = QLatin1String(__FUNCTION__) + u": "_qs + + func->classQualifiedSignature(); errorMsg = msgCouldNotFindMinimalConstructor(errorMsg, func->type().cppSignature(), errorMessage); diff --git a/sources/shiboken6/generator/shiboken/overloaddata.cpp b/sources/shiboken6/generator/shiboken/overloaddata.cpp index 103770396..1eb06b10b 100644 --- a/sources/shiboken6/generator/shiboken/overloaddata.cpp +++ b/sources/shiboken6/generator/shiboken/overloaddata.cpp @@ -37,6 +37,8 @@ #include "ctypenames.h" #include "pytypenames.h" #include "textstream.h" +#include "exception.h" +#include "messages.h" #include <QtCore/QDir> #include <QtCore/QFile> @@ -287,8 +289,10 @@ void OverloadDataRootNode::sortNextOverloads(const ApiExtractorResult &api) // Process inheritance relationships if (targetType.isValue() || targetType.isObject()) { - auto metaClass = AbstractMetaClass::findClass(api.classes(), - targetType.typeEntry()); + auto *te = targetType.typeEntry(); + auto metaClass = AbstractMetaClass::findClass(api.classes(), te); + if (!metaClass) + throw Exception(msgArgumentClassNotFound(m_overloads.constFirst(), te)); const AbstractMetaClassList &ancestors = metaClass->allTypeSystemAncestors(); for (const AbstractMetaClass *ancestor : ancestors) { QString ancestorTypeName = ancestor->typeEntry()->name(); |