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