sonar-delphi icon indicating copy to clipboard operation
sonar-delphi copied to clipboard

Default property parent overloading not handled

Open jgardn3r opened this issue 2 years ago • 1 comments

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

jgardn3r avatar Nov 10 '23 00:11 jgardn3r

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])

cirras avatar Nov 13 '23 09:11 cirras