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

qmlformat can not handle nested if

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • None
    • 5.15.0, 6.0
    • QML: Tooling
    • None
    • 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

            fawzi Fawzi Mohamed
            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