Shadowable member
This warning category is spelled [shadowable-member] by qmllint.
Member can be shadowed
What happened?
The compiler accesses a non-final property or method through an object whose exact type isn't known at compile time. A derived type might redeclare ("shadow") the member with a different type, and the QML engine would pick up that variant.
In the example below, the lookup for value on other can't be fully optimized because other might hold an object of a type deriving from Base that shadows value with a property of another type.
Why is that bad?
The compiler can't rely on the declared type of the member and has to treat it as var. The generated code is slower.
This category is enabled automatically if the compiler category is enabled, unless it is explicitly enabled or disabled.
Example
// Base.qml
import QtQml
QtObject {
property int value
}
// Main.qml
import QtQml
QtObject {
property Base other
property int v: other.value
}
Marking value as final guarantees that it can't be shadowed and allows the compiler to rely on the type it sees. In QML, use the final keyword:
// Base.qml
import QtQml
QtObject {
final property int value
}
In C++, declare the property FINAL:
Q_PROPERTY(int value READ value WRITE setValue NOTIFY valueChanged FINAL)
Alternatively, access the member through an object referenced by id, an attached property or a singleton, where the exact type is known.