Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/Compiler/Delphi/Code Generation/Optimization    [ Add a report in this area ]  
Report #:  76003   Status: Closed
A derived class can call non-existent overload of method via inherited keyword
Project:  Delphi Build #:  12.0.3420.21218
Version:    12.1 Submitted By:   CAS Developers
Report Type:  Minor failure / Design problem Date Reported:  7/22/2009 1:40:47 AM
Severity:    Infrequently encountered problem Last Updated: 3/20/2012 2:24:39 AM
Platform:    All versions Internal Tracking #:   271385
Resolution: Cannot Reproduce (Resolution Comments) Resolved in Build: : 15.0.3631.26671
Duplicate of:  None
Voting and Rating
Overall Rating: No Ratings Yet
0.00 out of 5
Total Votes: 4
Description
When an ancestor class provides overloaded versions of a method, descendant classes can call inherited with no parameters from a method with the same name, even when the parameter list is completely different. It doesn't seem that code is generated for that line but that is an issue by itself.

See steps.

Also, this is the scenario that leads to the TObjectList<T> access violation explained in 67272. TObjectList<T>.Create(OwnsObjects: Boolean) calls inherited, which compiles just fine. But since TList<T> doesn't have a constructor with that signature, no call whatsoever is made to an inherited constructor. This leads to the FComparer field not being assigned, as that happens in TList<T>.Create with no parameters. The way to fix that problem is to change TObjectList<T>.Create(OwnsObjects: Boolean) to call inherited Create instead. But that should never have compiled in the first place.
Steps to Reproduce:
Create two classes:

type
  TParentClass = class
  public
    procedure DoSomething;
  end;

  TChildClass = class(TParentClass)
  public
    procedure DoSomething(SomeParam1: string; SomeParam2: Integer);
  end;

and implement the function in TChildClass as follows:
procedure TChildClass.DoSomething(SomeParam1: string; SomeParam2: Integer);
begin
  inherited;
end;

Compiler error: [DCC Error] Unit1.pas(88): E2008 Incompatible types

Which is perfectly fine. But change TParentClass to this:
  TParentClass = class
  public
    procedure DoSomething; overload;
    procedure DoSomething(SomeParam: Boolean); overload;
  end;

and suddenly I get no compiler error! This misleads the developer to think the inherited function is being called when it really isn't.
Workarounds
None
Attachment
None
Comments

None

Server Response from: ETNACODE01