summaryrefslogtreecommitdiff
path: root/src/qmlcompiler
Commit message (Collapse)AuthorAgeFilesLines
...
* qmlsc: Support equality operations for QUrlSemih Yavuz2023-02-164-2/+25
| | | | | | | Task-number: QTBUG-110983 Pick-to: 6.5 Change-Id: I9a664178c91bfa2962e2a5a3bf4bfa174a74a9d0 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* qmllint: Fix attached property re-use detectionUlf Hermann2023-02-1414-76/+77
| | | | | | | | | | | | | | | | | | | | | Move the detection into the QtQuick lint plugin. It's mostly meant for QQC, so let's auto-enable it for attached types derived from QQuickAttachedPropertyPropagator. To this end, two new categories are introduced: The Quick lint plugin gets its own attached-property-reuse category which is synonymous to the default category of the same name. Furthermore, we add a controls-attached-property-reuse category for only checking controls. That one is implied by either of the others. Finally, fix the id vs. scope resolution to actually do something. This way we can give appropriate hints when the outer type has an ID already. Pick-to: 6.5 Fixes: QTBUG-110834 Change-Id: Ib71a9e3bbc10bac77f36db6cc441af88df20fd33 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* qmllint: Uncruftify FixSuggestionUlf Hermann2023-02-089-184/+216
| | | | | | | | | In this form we can expose it in QQmlSA. Pick-to: 6.5 Task-number: QTBUG-110834 Change-Id: Ieb0cf31b6e86379c0d80f89bc6c63b129f269798 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* qmlcompiler: Rephrase the "not found" messageUlf Hermann2023-02-071-2/+2
| | | | | | | | | If we can't find a member, we don't know whether it's a property. Pick-to: 6.5 Task-number: QTBUG-110933 Change-Id: Ie7d170f0e1967ac121630afe73e46c514b01e821 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* qmlcompiler: Deduplicate instructionManipulatesContext()Ulf Hermann2023-02-074-75/+25
| | | | | | | | | | We use it in three different compile passes, so it should be a member of QQmlJSCompilePass. Pick-to: 6.5 Change-Id: Ibc46ceb7ab05839b0a573c8ab3ee2acf4a6de154 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QmlCompiler: Consider attached types for "unused import" detectionUlf Hermann2023-02-071-1/+8
| | | | | | | | Pick-to: 6.5 Fixes: QTBUG-110833 Change-Id: Ie766c957a9ebeaea808fdc6904a1caea0e4cb849 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* qmllint: Provide import paths and resource files when linting modulesUlf Hermann2023-02-072-3/+14
| | | | | | | | | Those are just as important for modules as for single files. Pick-to: 6.5 Change-Id: I201d62c61988abc2dfba6300a1cfc355203fec75 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* QmlCompiler: Add hint about generalized grouped propertiesUlf Hermann2023-02-031-3/+9
| | | | | | | | | | | If a property cannot be found but there are immediate properties in the surrounding type, that indicates that the construct in question may be phrased using generalized grouped properties. Pick-to: 6.5 Fixes: QTBUG-105251 Change-Id: I107132294ba0ca56ff522fc29e7a1972553390bd Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* qmllint: Add warning about PropertyChanges using custom parserUlf Hermann2023-02-033-1/+17
| | | | | | | | | You should use the id-based generalized group form. Pick-to: 6.5 Fixes: QTBUG-105251 Change-Id: I42edfb03059d3e8c92bfb3c311bf1ed1af7cf70e Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* qmlcachegen: fix nonstrict equality code generationSemih Yavuz2023-01-314-11/+13
| | | | | | | | | | | | | | We should generate type checking code for only strict comparison of var against null/undefined types or vice versa cases. The non- strict comparison should be handled elsewhere. Removed pragma Strict to allow to add warning emitting tests of non-strict comparison. This amends 6a816a9e0dfc2b41a4f86c721679f2517ec27eb6 Pick-to: 6.5 Fixes: QTBUG-110769 Change-Id: I7f9a457e71a621a005f377216e841bec01667454 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QmlCompiler: Fix version resolution for importsUlf Hermann2023-01-301-2/+8
| | | | | | | | | | Partially versioned imports should not be sorted useing the generic comparison operators. We have to check each component individually. Pick-to: 6.5 Fixes: QTBUG-110320 Change-Id: Id75ab73ff6a4b5b040b9fcbb426e6bcf893d3d8b Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QML DOM: Remove support for Qt < 6.5Fabian Kosmale2023-01-305-45/+5
| | | | | | | | And build standalone DOM against Qt 6.5 (beta) Change-Id: I9395b4932ecdedd28f10d1e791e2abe445516183 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QML: Turn singleton/type mismatch into a run time type errorUlf Hermann2023-01-272-16/+13
| | | | | | | | | | | | | | | | | | | | | | | There are many ways to "hide" the qmldir from the engine at run time, which turns singletons into regular types. While all of this is invalid, we should not assert on it, but rather produce a legible warning. Furthermore, sharpen the importing of extra modules from qrc as implicit imports. We should really only import modules the file in question can ever be part of. Otherwise we needlessly produce the above situation and hide legitimate warning messages. Amends commit 7517c1b3ae9aa92f36b19d74a4b2de5e8531309b. Now we need to teach our tools about the default import paths in the resorurce file system. They cannot guess any type they may find in any resource file anymore. Pick-to: 6.5 Task-number: QTBUG-106929 Change-Id: Ic8c02396d10830a7f461e8a81649bb8c9a1add1f Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* qmllint: Do not warn when accessing properties of global constructorsFabian Kosmale2023-01-261-0/+16
| | | | | | | | | | | | | | | | | | | We are treating global constructor functions as methods. But while they are callable, they also have properties that can be accessed. Accessing those should not trigger any warning. However, prior to this commit, any property access to a method would yield a warning. As we don't store the list of known properties in the jsroot.qmltypes, we cannot really validate them. Moreover, it is also possilbe to extend the prototypes, so it might never be feasible to generate warnings. Thus, for now simply don't create warnings for JS globals in QQmlJSTypePropagator::isRestricted. Fixes: QTBUG-109204 Pick-to: 6.5 6.4 Change-Id: I992365ea716827a562886d7204b2401062772f9a Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* QmlCompiler: Wrap sequences with unknown elemnts in QVariantListUlf Hermann2023-01-231-0/+1
| | | | | | | | | | | Otherwise we later try to perform value type lookups on them. That won't work. Pick-to: 6.5 Task-number: QTBUG-110438 Change-Id: I1690a3375841ba5a1ff1a471a7f88bd2023ab4c4 Reviewed-by: Semih Yavuz <semih.yavuz@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* qmllint: Move qmlControlSanity loggers into a pluginSemih Yavuz2023-01-233-17/+0
| | | | | | | | | | | | | | QmlImportVisitor has some log messages that is only used for controls sanity tests. Move these loggers into a QuickControlsSanity plugin. Move the relevant tests from tst_qmllint to tst_sanity as we link the plugin to tst_sanity. Also remove qmlControlsSanity category from the default categories of QQmlJsLogger as it should be only utilised by this plugin. Task-number: QTBUG-103276 Change-Id: Iacc624711a2cd00aeb9d89fbde7c0131896d30ce Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QML: Add a pragma for value type behaviorUlf Hermann2023-01-204-20/+53
| | | | | | | | | | | Unfortunately value types behave differently when compiled to C++. Document the difference and introduce a pragma to make them behave one way or the other. Pick-to: 6.5 Fixes: QTBUG-109221 Change-Id: Ib2685153c0b4ae209bafbea7a01229377fdb47dd Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QmlCompiler: Handle various date and time conversions correctlyUlf Hermann2023-01-174-0/+39
| | | | | | | | | | | | | We can coerce QDateTime, QDate and QTime into each other because they would all be represented by a Date object in JavaScript. Furthermore we can coerce them all to QString. Technically, we could also coerce strings to all of them, but we don't want to because that is terrible. Fixes: QTBUG-109380 Change-Id: I176bfb5b715a6a6750cb5918c44261fa23fb8832 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* qmllint: Print fix suggestions for pragma ComponentBehaviorUlf Hermann2023-01-172-0/+13
| | | | | | | | | Pick-to: 6.5 Fixes: QTBUG-104576 Fixes: QTBUG-104632 Change-Id: I9e0919feb04798fb4c5d0c8c0ed2f5cbc7a0b552 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QQmlJSScope: Restrict disabling of bogus gcc warning to gcc 12 and 13Ulf Hermann2023-01-171-1/+1
| | | | | | | | | | | Earlier versions of gcc don't seem to know this warning. Amends commit 1d72f21415609ce7a8b665a71776d7ac26f1d4ee. Pick-to: 6.5 Change-Id: If7e78b84b0c3cd2190c33591f0fdc9e677489d66 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
* qmlls, qmllint: Avoid memory leaksUlf Hermann2023-01-162-14/+13
| | | | | | | Pick-to: 6.5 Fixes: QTBUG-104643 Change-Id: I5ca0fea2ef6f822b70c08bc6e49f0d07a732b299 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* Ignore a spurious -Wuse-after-free by GCCGiuseppe D'Angelo2023-01-131-0/+5
| | | | | | | | | | | | | | | | | | | | | GCC 13 seems to have a false positive here: In copy constructor 'QSharedPointer<T>::QSharedPointer(const QSharedPointer<T>&) [with T = const QQmlJSScope]', inlined from 'QDeferredSharedPointer<T>::QDeferredSharedPointer(QSharedPointer<T>) [with T = const QQmlJSScope]' at QQmlJSScope.cpp:33:11, inlined from 'Data::ConstPtr Data::get() const' at QQmlJSScope.cpp:244:37: /home/peppe/p/src/qt5/qtbase/build/include/QtCore/../../../src/corelib/tools/qsharedpointer_impl.h:296:80: warning: pointer used after 'void operator delete(void*)' [-Wuse-after-free] In static member function 'static void QtSharedPointer::ExternalRefCountData::operator delete(void*)', inlined from 'QWeakPointer<T>::~QWeakPointer() [with T = const QQmlJSScope]' at /home/peppe/p/src/qt5/qtbase/build/include/QtCore/../../../src/corelib/tools/qsharedpointer_impl.h:543:60, inlined from 'QWeakPointer<T>::~QWeakPointer() [with T = const QQmlJSScope]' at /home/peppe/p/src/qt5/qtbase/build/include/QtCore/../../../src/corelib/tools/qsharedpointer_impl.h:543:12, inlined from 'QSharedPointer<T> QDeferredWeakPointer<T>::toStrongRef() const [with T = const QQmlJSScope]' at QQmlJSScope.cpp:186:16, inlined from 'Data::ConstPtr Data::get() const' at QQmlJSScope.cpp:244:36: /home/peppe/p/src/qt5/qtbase/build/include/QtCore/../../../src/corelib/tools/qsharedpointer_impl.h:130:67: note: call to 'void operator delete(void*)' here This makes qtdeclarative FTBFS in release builds. Pick-to: 6.5 Change-Id: If7a7565a68a7eaa0770c41e4e7ad1288b460e7ef Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Remove redundant std::move() detected by GCC 13Thiago Macieira2023-01-111-2/+2
| | | | | | | | | | | QQmlJSScope::ContextualTypes::types() returns a QHash by const- reference, which can't be made rvalue. qqmljsimporter.cpp:581:71: warning: redundant move in initialization [-Wredundant-move] Pick-to: 6.5 Change-Id: Ide4dbd0777a44ed0870efffd17394924871c28c6 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QmlCachegen: Equality comparison ability to QObject *Semih Yavuz2023-01-104-2/+36
| | | | | | | | | | We should be able to compare QObject * with QObject * or a nullptr. Pick-to: 6.5 Fixes: QTBUG-109377 Change-Id: I0e9d6fdc89cbb471774d6382316dfb4813310e1d Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QmlCachegen: Equality comparison ability to var and void/null typesSemih Yavuz2023-01-065-3/+119
| | | | | | | | | | | | | | | The code generator currently rejects any comparisons other than primitive types. Add comparison capability for var types against null or undefined types and vice versa. To achieve this, we generate code that fetches the contained object within the variant and comparison is done depending on the stored type. Ideally, we also need to add comparison capability for QObject *, that will be handled with QTBUG-109377. Pick-to: 6.5 Fixes: QTBUG-108632 Change-Id: Ib15450d7922f6025c78def5cc548c74827ad740f Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Fix some qsizetype vs. quint32 problemsUlf Hermann2023-01-061-1/+1
| | | | | | | | | | On 32bit platforms you cannot losslessly convert quint32 to qsizetype. However, in the places we are facing here, we are only interested in signed 32bit numbers anyway. Pick-to: 6.5 6.2 Change-Id: I93a07c2847bd5bfae426dccbb6c0e33c5758442d Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QmlCompiler: std::move() registers where possibleUlf Hermann2022-12-238-107/+189
| | | | | | | | | | | | In the common case that we read a register only once, in the same basic block, generate a std::move() in order to move it into place. Especially for QVariants holding large internal objects, this should help performance. Fixes: QTBUG-101452 Change-Id: I015892e1046ca7b739dbd296756f3f012dba5f9b Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* QmlCompiler: Fix signal checking in import visitorUlf Hermann2022-12-152-162/+171
| | | | | | | | | | | | We can determine that a binding that looks like a signal handler on first glance is not a signal handler after all. In that case we should not warn about it. Furthermore, we don't need to store all the signal handlers several times over. Pick-to: 6.5 Fixes: QTBUG-109021 Change-Id: I4b90254faa7644df047f29c98f126977a90f6662 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QmlCompiler: Fix recognition of builtin list typesUlf Hermann2022-12-151-2/+11
| | | | | | | | | | | | | Previously all list types used as arguments or return types for methods had to be looked up via the imports. However, builtin types are not part of the imports at run time. Therefore, recognize list types already early on, when generating the IR. This is the same way we do it for property types and it allows us to easily identify lists of builtins. Pick-to: 6.5 Fixes: QTBUG-109147 Change-Id: I91fa9c8fc99c1e0155cc5db5faddd928ca7fabbc Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QmlCompiler: Fix wrapping of numbers in QJSPrimitiveValueUlf Hermann2022-12-151-3/+15
| | | | | | | | | | | | | | | | | | We need to explicitly cast to double if we are wrapping a number type that's not natively accepted by the ctors. As a side effect, correctly run conversions from generic QVariant to QJSPrimitiveValue through the engine now. For that we need another clause in metaTypeFromJS(). Since we are calling methods that return list types in the test, we need to add another clause that converts JS arrays to list types. Otherwise we cannot run that test in interpreted mode. Pick-to: 6.5 6.2 6.4 6.4.2 Task-number: QTBUG-109111 Change-Id: I87f7aafd24371d2c1ffe85569e1f2cd3a1979742 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QmlCompiler: Mark StoreElement on JS values has having side effectsUlf Hermann2022-12-151-0/+4
| | | | | | | | | | A StoreElement on a JS value can do pretty much anything you can imagine, after all. Pick-to: 6.5 6.4 6.4.2 Fixes: QTBUG-109196 Change-Id: Ic638d94b55e6340eb9fe56abc663a6f0f2277f5e Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QQmlJSCodeGenerator: fix nullptr dereferenceFabian Kosmale2022-12-121-0/+7
| | | | | | | | | | | | | If we try to lookup the length of a generic QVariant, we fail, and so far crashed. We should ideally detect that we are dealing with an array (and thus length is a known, available property), but for now simply reject compilation to C++. Pick-to: 6.4 Fixes: QTBUG-109164 Change-Id: I9d4149ac09a351754d012dbc829774413d6b32eb Reviewed-by: Semih Yavuz <semih.yavuz@qt.io> Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* qmllint: Read the right register when analyzing callsUlf Hermann2022-12-091-2/+3
| | | | | | | | | | CallProperty does not use the accumulator. Pick-to: 6.4 6.4.2 Fixes: QTBUG-109144 Change-Id: I2bd98bb3a66d68806d250bd50226a8f8e0cdf765 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* qmltc: fix handlers for c++-signalsSami Shalayel2022-12-075-4/+73
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Allow qmltc to generate handlers for c++-defined signals with const parameters by changing the safeguard to avoid type mismatch between slots and signals. First, remove the qOverload in the generated QObject::connect call to be able the connect slots and signals with different types (namely, pass by const references and pass by value should be interchangeable but is not allowed by qOverload). Second, save in QQmlJSMetaParameter when types are passed by pointer. Like this, qqmljsimportvisitor can check if a value type is indeed passed by value or const reference in a C++ signal. The same for reference types that need to be passed by (const and non-const) pointer. Print a message when an type is passed by argument in an incompatible way instead of letting qmltc generate uncompilable code, which makes the compiler print out cryptical messages. Third, add a qqmlcpptypehelpers template that decides if value types should be passed by value or reference, by letting the c++ compiler check if sizeof(T) > 3*sizeof(void*). Fixes: QTBUG-107625 Fixes: QTBUG-107622 Change-Id: I1a00532df591d10f74c1fd00dff5b7fccf40cb22 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QmlCompiler: Ignore cloned signals when analyzing signal handlersUlf Hermann2022-12-071-0/+2
| | | | | | | | | We obviously want to see the defaulted parameters when generating the handlers. Fixes: QTBUG-108762 Change-Id: I33a52bac305238467d45650bf8a2ad59d40e366f Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Mark the module free of qAsConst()Marc Mutz2022-12-052-2/+2
| | | | | | Change-Id: I914ccc09297ac6283d7cf24d5afc96ebdaf294d0 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QQmlJSImportVisitor: Do not deref potentially null typeFabian Kosmale2022-12-051-9/+10
| | | | | | | | | | When checking for default properties, a type may not be resolved (due to a missing import). So check for that first before checking that the type is a list property. Fixes: QTBUG-109197 Change-Id: Idc142588b5d8bc52fdea52d637afc3643e7d9891 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* qmltyperegistrar: Propagate the "isCloned" flag through qmltypesUlf Hermann2022-12-052-1/+7
| | | | | | | Task-number: QTBUG-108762 Change-Id: I916ec32329bccfff89a93a57aaca183e3f798197 Reviewed-by: Semih Yavuz <semih.yavuz@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QmlCompiler: Fix various kinds of enum lookupUlf Hermann2022-12-023-4/+34
| | | | | | | | | | | | | | | | | * If we got an object type exposed as namespace, we still need to add the "*" to get its augmentedInternalName(). Otherwise we cannot get its metaobject, needed to look up enums. * Enums cannot be shadowed. The shadow check will produce garbage if we try to check because an enum lookup also does not use the accumulator, which then contains some artifact from a previous operation. * If we find a property lookup on a plain QMetaObject* we have to immediately return in order to not confuse it with attached properties. Pick-to: 6.4 6.2 Fixes: QTBUG-109048 Change-Id: If9e3b4806e4d773de9cf48f1b3750b684a8c8f69 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QQmlJSMetaParameter: Encapsulate parameter informationSami Shalayel2022-12-027-96/+117
| | | | | | | | | | | | | | | | | | | Previously, there were four lists that contained each one entry for each parameter. There was one list responsible for the names, types, type names and const-qualifiers but this was quite bothersome to use (e.g. they not always had the same length). This commit introduces QQmlJSMetaParameter to encapsulate all the information required when manipulating parameters. This reduce the 4 lists to one, making parameters easier to handle and QQmlJSMetaMethod easier to read. This is a purely refactoring change, no new functionality was added. Task-number: QTBUG-107625 Change-Id: Ia41b823c9e6294ee26e828071b802cac6b4058ce Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QmlCompiler: Pass QVariant as-is to functions accepting varUlf Hermann2022-12-011-1/+2
| | | | | | | | | The QML engine will helpfully re-assemble our variant if we pass it in pieces, but we should not rely on this. Fixes: QTBUG-109005 Change-Id: I35d10b4ee61a0426049986bc6f83d6c880ddc281 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QmlCompiler: Do not print context for source locations of length 0Ulf Hermann2022-11-302-3/+4
| | | | | | | | We generally print a second message to clarify the context anyway. Fixes: QTBUG-108851 Change-Id: Iba392f2983498ecb1d780034523feab8d9057b84 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QmlCompiler: Check return code when opening qmltypes filesUlf Hermann2022-11-291-1/+9
| | | | | | | Coverity-Id: 403059 Change-Id: Ic45f749602f4230e8319d0c3d4c262043d2cdad4 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* QmlCompiler: Store imported types in a QListUlf Hermann2022-11-254-24/+40
| | | | | | | | | | | | | | | The same type can be exported multiple times with different attributes, even in the same module. This requires us to fix directory imports as qmllint otherwise complains about SegFault.bad.qml and SegFault.qml being the same type (which they obviously aren't). Task-number: QTCREATORBUG-27590 Change-Id: I295d927b9a07acbb715055a6883ac44b50129c2d Reviewed-by: Sami Shalayel <sami.shalayel@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* QQmlJSImportVisitor: warn when uncreatables are createdSami Shalayel2022-11-236-8/+61
| | | | | | | | | | | | | | | | | | | | | | isCreatable in qqmljsscope just returns the value of the flag as it was read from the qmltypes, which is slightly confusing as isCreatable is an opt-out option. Instead, isCreatable should reflect whether the type is creatable or not. A type is uncreatable if and only if it is a singleton, an attached type, a c++ type with QML_UNCREATABLE and types without default constructor. This uncreatibility can also be inherited to composite types. Types without default constructor require QML_UNCREATABLE or QML_ANONYMOUS, and will be handled in another commit. Now that uncreatable types can be detected, emit a warning when a singleton or an uncreatable type is created: up to now no such warning was emitted. This warning can be seen when using qmllint or qmltc. By the way, also fix qmltc to not assert when something goes wrong (e.g. because an uncreatable or singleton type was created). Change-Id: I9a82106a801d14063407eb4e54858b1ca9fd578b Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QmlCompiler: Implement console logging methodsUlf Hermann2022-11-233-0/+134
| | | | | | | | | | | We provide semi-private functions in the AOT context for this. Since we cannot know the complete run time type of the potential logging category at compile time, we have to check any first argument that might be one separately. Fixes: QTBUG-107175 Change-Id: I46a8922b1c5c16d2b450b8728d650d31dfd867e3 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QmlCompiler: Fix comparison of null and undefinedUlf Hermann2022-11-231-11/+21
| | | | | | | | | | | | Those are not stored. If we compare null to null or undefined to undefined, we do not have to generate a comparison at all. the result is statically known. Pick-to: 6.4 Fixes: QTBUG-108634 Change-Id: I6a5323c2e0c023838609aec90d7ecc15b885dc08 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* qqmljsscope: resolve enums using their aliasesSami Shalayel2022-11-231-0/+23
| | | | | | | | | | | | | | | | | | | | Some enums happen to have an alias, e.g. when an enum is used as a flag, the enum will exist in two versions, once as enum (e.g. Qt::MouseButton) and once as a flag (e.g. Qt::MouseButtons). In this case, normally only the flag is exposed to the qt metatype system and tools like qmltc will have troubles when encountering the enum in signal parameters etc. To solve this problem, QQmlJSScope::resolveEnums() will create a QQmlJSMetaEnum copy for the alias in case the 'self'-scope already does not have an enum called like the alias. For the greater picture: this allows qmltc to compile signal handlers for signals that take enums as argument without asserting, and also is a step forward to compile the quick/text example with qmltc. Task-number: QTBUG-107609 Change-Id: I8fcb48a15a2066fb2d2dc89fc26b8441a1a0f489 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* qmltc: add singleton supportSami Shalayel2022-11-231-5/+1
| | | | | | | | | | | | Add singleton support to qmltc. Add the QML_SINGLETON annotation to the class, generate a static T* create(QQmlEngine*, QJSEngine*) method for the engine and also add test this new functionality. Fixes: QTBUG-106828 Change-Id: I7b6b39ab0c8a427b3166562c3f04cf4a7eaa20e2 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QJSEngine: Optimize conversion from QObject* to QStringUlf Hermann2022-11-221-0/+5
| | | | | | | | | | | | | | | This is commonly done for logging. With this in place we can have the code generator use coerceType() for such constructs. [ChangeLog][QML][Important Behavior Changes] You can implement custom toString() methods for your QML objects in JavaScript or in C++. Those methods don't actually have to return a string. Previously, whatever return value the method generated was forwarded as-is. Now it is coerced to a string. Change-Id: I4a9721a6948be0c24a36b31d453a74bd747db729 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>