Details
-
Bug
-
Resolution: Fixed
-
P2: Important
-
6.8.1
-
None
-
caa553414 (dev), db9ebe66e (6.9), c6c39d9f5 (6.8)
Description
Take the following example code:
import QtQuick import QtQuick.Controls import QtQuick.Layouts Container { id: root readonly property var backendObject contentItem: ColumnLayout { Repeater { model: ["red", "green", "blue"] Text { Layout.fillWidth: true text: { const notAvailable = "N/A"; return root.backendObject.results?.[modelData].text ?? notAvailable; } } } } }
After running `qmlformat` the line
return root.backendObject.results?.[modelData].text ?? notAvailable;
is changed to
return root.backendObject.results[modelData].text ?? notAvailable;
Note how the optional chaining (`?.`) is completely dropped.
In the likely case that this object is not available from the backend, this change would result in the error `Uncaught TypeError cannot read properties of null` instead of just returning `"N/A"`.