Details
-
Bug
-
Resolution: Unresolved
-
P1: Critical
-
6.5.0 RC
-
None
Description
Consider:
pragma Strict import QtQuick import QtQuick.Window Window { width: 640 height: 480 title: qsTr("Hello World") component B: Item { function contains(point: point) : string { console.log("b", point.x, point.y) return "b" } } component C: Item { function contains(point: point) : string { console.log("c", point.x, point.y) return "c" } } property Item a: Item {} property B b: B {} property C c: C {} function doThing() { console.log(a.contains(Qt.point(0, 0))) } Component.onCompleted: { doThing(); a = b; doThing(); a = c; doThing(); Qt.quit(); } }
Expected output:
qml: false
qml: b 0 0
qml: b
qml: c 0 0
qml: c
Output when compiled to C++:
qml: false qml: b 0 0 qml: true qml: c 0 0 qml: true
So, the call actually gets resolved to the right method and the engine will coerce the types as necessary. However, the generated code expects to receive a bool as the method on QQuickItem tells it.
There are three ways out of this:
- Disable calls to potentially shadowed methods
- When calling potentially shadowed methods treat all parameters and return values as var, weakening type inference.
- Document the difference and accept it.