integrated-application-development / integrated-application-development/sonar-delphi

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

Open
#271 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
Java
Stars
159
Forks
31
Avg merge
5d 4h
Merged PRs (30d)
4

Description

### 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

```pas
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.
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.