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

Bare `inherited` fails to resolve parent `message` handler with different signature

Open Cirras opened this issue 7 months 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

1.7.0

SonarQube version

No response

Issue description

SonarDelphi does not currently implement the following behavior around message handlers.

When inherited has no identifier after it, it refers to the inherited method with the same name as the enclosing method or, if the enclosing method is a message handler, to the inherited message handler for the same message. In this case, inherited takes no explicit parameters, but passes to the inherited method the same parameters with which the enclosing method was called.

See https://docwiki.embarcadero.com/RADStudio/Athens/en/Methods_(Delphi)#Inherited

Steps to reproduce

In the below code example, the inherited in TBar.Bar should resolve to TFoo.Foo.

Minimal Delphi code exhibiting the issue

unit Example;

interface

type
  TFoo = class(TObject)
    procedure Foo(var Msg: TWMSize); message WM_SIZE;
  end;

  TBar = class(TFoo)
    procedure Bar(var Msg: TMessage); message WM_SIZE;
  end;

implementation

procedure TFoo.Foo(var Msg: TWMSize);
begin
  // ...
end;

procedure TBar.Bar(var Msg: TMessage);
begin
  inherited; // This should call TFoo.Foo
  // ...
end;

end.

Cirras avatar Jul 19 '24 06:07 Cirras