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

Missing return type annotation in qml changes return to void

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P3: Somewhat important P3: Somewhat important
    • None
    • 6.6.1, 6.6.3
    • None

      If a function has only input parameter type annotation without a return type, it is possible that the function is compiled as void, even though qml explicitly returns something. Take the following code for example:
      Having the type annotation "Flickable", without any return type annotation, results in this function ALWAYS returning undefined in qml. The code below always returns undefined when called from qml.

      function getNewScale(childRectangle: rect, flickable: Flickable) {
           let xScale = flickable.contentWidth / childRectangle.width
           let yScale = flickable.contentHeight / childRectangle.height
           return Math.min(xScale, yScale)
      }
      

      Adding the return type annotation ": real" fixes the problem, but this feels like it should not be allowed to happen. The code below always returns the expected real value.

      function getNewScale(childRectangle: rect, flickable: Flickable) : real {
           let xScale = flickable.contentWidth / childRectangle.width
           let yScale = flickable.contentHeight / childRectangle.height
           return Math.min(xScale, yScale)
      }
      

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

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            r.vitanov Rosen Vitanov
            Votes:
            2 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:

                There are no open Gerrit changes