[new compiler] Fix error message when trying to create uncreatable types
Pass along the no-creation-reason properly, for regular qml types as well as singleton types. Also don't collect custom signal parameter names as types to resolve, as we never try to instantiate them anyway. Their type resolution to meta-type id is done lazily when building the meta-objects. Change-Id: I49bd51d9b851cf75cbd51afbcee168944f4350cd Reviewed-by: Lars Knoll <lars.knoll@digia.com>
This commit is contained in:
parent
72fffeb2c1
commit
6ae57f01bb
|
@ -1020,15 +1020,13 @@ void QQmlCodeGenerator::collectTypeReferences()
|
|||
_typeReferences.add(obj->inheritedTypeNameIndex, obj->location);
|
||||
|
||||
for (QmlProperty *prop = obj->properties->first; prop; prop = prop->next) {
|
||||
if (prop->type >= QV4::CompiledData::Property::Custom)
|
||||
_typeReferences.add(prop->customTypeNameIndex, prop->location);
|
||||
if (prop->type >= QV4::CompiledData::Property::Custom) {
|
||||
// ### FIXME: We could report the more accurate location here by using prop->location, but the old
|
||||
// compiler can't and the tests expect it to be the object location right now.
|
||||
_typeReferences.add(prop->customTypeNameIndex, obj->location);
|
||||
}
|
||||
}
|
||||
|
||||
for (Signal *sig = obj->qmlSignals->first; sig; sig = sig->next)
|
||||
for (SignalParameter *param = sig->parameters->first; param; param = param->next)
|
||||
if (!stringAt(param->customTypeNameIndex).isEmpty())
|
||||
_typeReferences.add(param->customTypeNameIndex, param->location);
|
||||
|
||||
for (Binding *binding = obj->bindings->first; binding; binding = binding->next) {
|
||||
if (binding->type == QV4::CompiledData::Binding::Type_AttachedProperty)
|
||||
_typeReferences.add(binding->propertyNameIndex, binding->location);
|
||||
|
|
|
@ -80,13 +80,36 @@ bool QQmlTypeCompiler::compile()
|
|||
const QHash<int, QQmlTypeData::TypeReference> &resolvedTypes = typeData->resolvedTypeRefs();
|
||||
for (QHash<int, QQmlTypeData::TypeReference>::ConstIterator resolvedType = resolvedTypes.constBegin(), end = resolvedTypes.constEnd();
|
||||
resolvedType != end; ++resolvedType) {
|
||||
QQmlCompiledData::TypeReference *ref = new QQmlCompiledData::TypeReference;
|
||||
QScopedPointer<QQmlCompiledData::TypeReference> ref(new QQmlCompiledData::TypeReference);
|
||||
QQmlType *qmlType = resolvedType->type;
|
||||
if (resolvedType->typeData) {
|
||||
if (qmlType->isCompositeSingleton()) {
|
||||
QQmlError error;
|
||||
QString reason = tr("Composite Singleton Type %1 is not creatable.").arg(qmlType->qmlTypeName());
|
||||
error.setDescription(reason);
|
||||
error.setColumn(resolvedType->location.column);
|
||||
error.setLine(resolvedType->location.line);
|
||||
recordError(error);
|
||||
return false;
|
||||
}
|
||||
ref->component = resolvedType->typeData->compiledData();
|
||||
ref->component->addref();
|
||||
} else {
|
||||
ref->type = resolvedType->type;
|
||||
} else if (qmlType) {
|
||||
ref->type = qmlType;
|
||||
Q_ASSERT(ref->type);
|
||||
|
||||
if (!ref->type->isCreatable()) {
|
||||
QQmlError error;
|
||||
QString reason = ref->type->noCreationReason();
|
||||
if (reason.isEmpty())
|
||||
reason = tr("Element is not creatable.");
|
||||
error.setDescription(reason);
|
||||
error.setColumn(resolvedType->location.column);
|
||||
error.setLine(resolvedType->location.line);
|
||||
recordError(error);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ref->type->containsRevisionedAttributes()) {
|
||||
QQmlError cacheError;
|
||||
ref->typePropertyCache = engine->cache(ref->type,
|
||||
|
@ -96,7 +119,6 @@ bool QQmlTypeCompiler::compile()
|
|||
cacheError.setColumn(resolvedType->location.column);
|
||||
cacheError.setLine(resolvedType->location.line);
|
||||
recordError(cacheError);
|
||||
delete ref;
|
||||
return false;
|
||||
}
|
||||
ref->typePropertyCache->addref();
|
||||
|
@ -104,7 +126,7 @@ bool QQmlTypeCompiler::compile()
|
|||
}
|
||||
ref->majorVersion = resolvedType->majorVersion;
|
||||
ref->minorVersion = resolvedType->minorVersion;
|
||||
compiledData->resolvedTypes.insert(resolvedType.key(), ref);
|
||||
compiledData->resolvedTypes.insert(resolvedType.key(), ref.take());
|
||||
}
|
||||
|
||||
// Build property caches and VME meta object data
|
||||
|
|
|
@ -67,6 +67,8 @@ struct Location;
|
|||
|
||||
struct QQmlTypeCompiler
|
||||
{
|
||||
Q_DECLARE_TR_FUNCTIONS(QQmlTypeCompiler)
|
||||
public:
|
||||
QQmlTypeCompiler(QQmlEnginePrivate *engine, QQmlCompiledData *compiledData, QQmlTypeData *typeData, QtQml::ParsedQML *parsedQML);
|
||||
|
||||
bool compile();
|
||||
|
|
Loading…
Reference in New Issue