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"`.
Attachments
For Gerrit Dashboard: QTBUG-132280 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
620709,6 | qmlformat: Preserve "?." tokens for various member access expressions | dev | qt/qtdeclarative | Status: MERGED | +2 | 0 |
621184,2 | qmlformat: Preserve "?." tokens for various member access expressions | 6.9 | qt/qtdeclarative | Status: MERGED | +2 | 0 |
621721,2 | qmlformat: Preserve "?." tokens for various member access expressions | 6.8 | qt/qtdeclarative | Status: MERGED | +2 | 0 |