Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-109048

qmlsc crashes with enum method parameters

    XMLWordPrintable

Details

    • 8bc748e7e (dev), 1253afac7 (6.4)

    Description

      This is a follow up of QTBUG-108883 which contains two problems in one. The attached example code has stripped down C++ side model stuff and a pseudo factory to create instances of it:

      class Foo : public QObject {
          Q_OBJECT
          
      public:     
          enum Type {
              Unknown,
              Fighter,
              Grid
          };
          Q_ENUM(Type)
          
          explicit Foo(Foo::Type type, QObject *parent = nullptr) : QObject(parent), m_type(type) {}
          
      private:
          Type m_type = Type::Unknown;
      
          Q_DISABLE_COPY(Foo)
      };
      
      namespace FooWrapper {
          Q_NAMESPACE
          QML_FOREIGN_NAMESPACE(Foo)
          QML_NAMED_ELEMENT(Foo)
      };
      
      class FooThingWrapper {
          Q_GADGET
          QML_FOREIGN(Foo)
          QML_NAMED_ELEMENT(fooThing)
          QML_UNCREATABLE("nope")
      };
      
      class FooFactory : public QObject {
          Q_OBJECT
          QML_ELEMENT
      public:
          Q_INVOKABLE Foo* get(Foo::Type type) const { return new Foo(type); }
      };
      

      . The factory is no singleton by purpose to trigger the issue. When using this in QML

      import QtQuickWindow {
          id: root
          width: 640
          height: 480
          visible: true
          title: "Foo"
      
          readonly property FooFactory f: FooFactory {}
      
          Item {
              readonly property fooThing fighter: root.f.get(Foo.Grid)
              readonly property fooThing bar: root.f.get(Foo.Fighter)
          }
      }
      

      , the compiler first complains about "Foo.Grid" (seems to be interpreted as an attached property) and then asserts when assigning "Foo.Fighter":

      Warning: main.qml:13:52: Could not compile binding for fighter: argument 0 contains QQuickPositionerAttached of QQuickPositionerAttached but is expected to contain the type Foo::Type [compiler]
              readonly property fooThing fighter: root.f.get(Foo.Grid)
                                                         ^^^
      ASSERT: "m_typeResolver->isPrefix(memberName)" in file /home/prcs1076/Projekte/qt6/qtdeclarative/src/qmlcompiler/qqmljsshadowcheck.cpp, line 96
      

      .

      Reproducible with 6.5 from maintenance tool or git dev.

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              ulherman Ulf Hermann
              cajus Cajus Pollmeier
              Votes:
              1 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes