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

qmlformat can not handle nested if

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P2: Important
    • Resolution: Done
    • Affects Version/s: 5.15.0, 6.0
    • Fix Version/s: None
    • Component/s: QML: Tooling
    • Labels:
      None
    • Commits:
      ac68310b7857693c9eb7ccb782133ac9ec8e2328 (qt/qtdeclarative/dev)

      Description

      See simplified version of code bellow.
      qmlformat from "dev" and qmlformat from 5.15 prints:

      Failed to parse formatted code.
      An error has occurred. Aborting.
      

      If I add curly brackets around outer "if", qmlformat can handle this code,
      but only once.

      import QtQuick 2.0
      
      Item {
          function f(x, y) {
              if (x && y)
                  if (x < y)
                      return 0;
                  else
                      return -1;
      
              else 
                  return y;
          }
      }
      

      I mean if add:

      import QtQuick 2.0
      
      Item {
          function f(x, y) {
              if (x && y) {
                  if (x < y)
                      return 0;
                  else
                      return -1;
      
              } else {
                  return y;
              }
          }
      }
      

      qmlformat can parse this code,
      but it removes "{" that fixed this code,
      so if you run qmlformat -i test.qml , the second run failed.

        Attachments

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

          Activity

            People

            Assignee:
            fawzi Fawzi Mohamed
            Reporter:
            evgeniy_dushistov evgeniy_dushistov
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Gerrit Reviews

                There are no open Gerrit changes