sonar-delphi
sonar-delphi copied to clipboard
Default property parent overloading not handled
Prerequisites
- [X] This bug is in SonarDelphi, not SonarQube or my Delphi code.
- [X] This bug has not already been reported.
SonarDelphi version
0.40.0
SonarQube version
No response
Issue description
Consider a parent with a default index property called Items and a child class with a default index property with the same name. When the types of the index property differ, the default property use can resolve to both parent and child declarations.
This issue manifests in a few ways, but an example is the Default array properties should not be explicitly referenced check. It will raise an issue on the child's index reference and not the parent's.
Steps to reproduce
type
TParent = class(TObject)
...
property Items[Index: Integer]: Integer read GetItem write SetItem; default;
end;
TChild = class(TParent)
...
property Items[Index: String]: Integer read GetItem write SetItem; default;
end;
begin
TChild.Create.Items['a']; // Noncompliant
TChild.Create.Items[1]; // Falsely compliant
end
Minimal Delphi code exhibiting the issue
No response
Funny enough, the analyzer actually tries to handle this (see StructTypeImpl::findDefaultArrayProperties.
Erroneously, it only does so if the property access is implicit. (e.g. TChild.Create[1])