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

Check ahead of time (in qmllint) that extension type are not shadowed

    XMLWordPrintable

Details

    Description

      Extension types on Q_OBJECTs are fairly special. [1] documented that members of extension types are implicitly FINAL (as in final properties).
      We should be able to check that no shadowing happens ahead of time in QQmlJSImportVisitor which is used by qmllint and compilers (qmlsc, qmltc).

      Doing the analysis at run time in QQmlComponent case is rather costly and it would technically be a behavior change as QML-created properties shadow extension types quite well - something that e.g. qmltc doesn't want to support. In C++ land, however, an extension type property would always shadow any other same-named property (same for signals / methods, etc.).

      Thus, what we can sanely do is make qmllint warn if properties are shadowed. Something like the following thus should be warned about:

      // C++:
      class Extension : public QObject
      {
        Q_PROPERTY(int x ...)
        Q_PROPERTY(int y ...)
        ...
      };
      class Base : public QObject
      {
        QML_EXTENDED(Extension)
        ...
      };
      class Derived : public Base
      {
        Q_PROPERTY(int x ...) // shadows extension type property!
        ...
      };
      
      // QML:
      
      Derived {
        x: 42 // sets (should at least - needs testing) 'x' property of Extension type
        // Warning: 'x' from Derived shadows extension type property 'x'
      
        property int y
        y: 42 // QQmlComponent: sets 'y' property of QML type, not Extension type
                  // qmltc: sets 'y' property of Extension type
        // Warning: 'y' from this object shadows extension type property 'y'
      }
      

      List of extension type "members" to care about (possibly not exhaustive):

      1. properties
      2. Q_INVOKABLE methods
      3. signals
      4. enums

      [1]: b85ac05e4ab3ef356ef59f6c57f44855edf15c5c

      Attachments

        Issue Links

          For Gerrit Dashboard: QTBUG-104007
          # Subject Branch Project Status CR V

          Activity

            People

              qtqmlteam Qt Qml Team User
              agolubev Andrei Golubev
              Vladimir Minenko Vladimir Minenko
              Alex Blasche Alex Blasche
              Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There is 1 open Gerrit change