22 const QQmlSA::Element &fromElement,
23 const QQmlSA::Element &toElement)
26 auto from = QQmlJSScope::scope(fromElement);
27 auto to = QQmlJSScope::scope(toElement);
31 if (!resolver->canConvertFromTo(from, to))
34 const bool fromIsString = from == resolver->stringType();
36 if (to == resolver->stringType()
37 || to == resolver->stringListType()
38 || to == resolver->byteArrayType()
39 || to == resolver->urlType()) {
43 if (resolver->isNumeric(to))
44 return resolver->isNumeric(from);
46 if (to == resolver->boolType())
47 return from == resolver->boolType();
67 case QQmlSA::BindingType::BoolLiteral:
69 case QQmlSA::BindingType::NumberLiteral:
71 case QQmlSA::BindingType::StringLiteral:
73 case QQmlSA::BindingType::RegExpLiteral:
75 case QQmlSA::BindingType::Null:
80 Q_UNREACHABLE_RETURN(QString());
84 const QQmlSA::Binding &binding,
85 const QQmlSA::Element &bindingScope)
const
87 if (!QQmlSA::Binding::isLiteralBinding(binding.bindingType()))
90 const QString unqualifiedPropertyName = [&propertyName]() -> QString {
91 if (
auto idx = propertyName.lastIndexOf(u'.'); idx != -1 && idx != propertyName.size() - 1)
92 return propertyName.sliced(idx + 1);
96 return bindingScope.property(unqualifiedPropertyName);
100 const QQmlSA::Binding &binding,
const QQmlSA::Element &propertyType)
102 auto construction = check(propertyType.internalId(), binding.stringValue());
103 if (!construction.isValid())
106 const QString warningMessage =
107 u"Construction from string is deprecated. Use structured value type "
108 u"construction instead for type \"%1\""_s.arg(propertyType.internalId());
110 if (construction.code.isEmpty()) {
111 emitWarning(warningMessage, qmlIncompatibleType, binding.sourceLocation());
115 const QQmlSA::FixSuggestion suggestion(
116 u"Replace string by structured value construction"_s,
117 binding.sourceLocation(),
118 { binding.bindingScope().filePath(), binding.sourceLocation(), construction.code });
119 emitWarning(warningMessage, qmlIncompatibleType, binding.sourceLocation(), suggestion);
123 const QString &propertyName,
124 const QQmlSA::Binding &binding,
125 const QQmlSA::Element &bindingScope,
126 const QQmlSA::Element &value)
130 const auto property = getProperty(propertyName, binding, bindingScope);
131 if (!property.isValid())
136 if (property.isReadonly() && !element.hasOwnProperty(propertyName)) {
137 emitWarning(u"Cannot assign to read-only property %1"_s.arg(propertyName),
138 qmlReadOnlyProperty, binding.sourceLocation());
142 if (
const auto propertyType = property.type())
143 warnOnCheckedBinding(binding, propertyType);
145 if (!canConvertForLiteralBinding(m_resolver, resolveLiteralType(binding), property.type())) {
146 emitWarning(u"Cannot assign literal of type %1 to %2"_s.arg(
147 literalPrettyTypeName(binding.bindingType()),
148 QQmlJSScope::prettyName(property.typeName())),
149 qmlIncompatibleType, binding.sourceLocation());