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

Missing return type annotation in qml changes return to void

    XMLWordPrintable

Details

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

    Description

      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)
      }
      

      Attachments

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

        Activity

          People

            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

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes