Incorrect override resolution from overloaded constructor

Issue #81 resolved
Former user created an issue

The following declarations, declared in a TdwsUnit, causes a compile time error:

Syntax Error: Unit: "Test"
Class: "TProblem"
Constructor: "Create"
Inherited method "Create" isn't virtual. "override" not applicable

unit test;

type
  TBase = class
    constructor Create; virtual; abstract;
  end;

type
  TDerived = class(TBase)
    constructor Create(Value: boolean); overload; begin end;
    constructor Create; overload; override; begin end;
  end;

type
  TProblem = class(TDerived)
    constructor Create; override; begin end;
  end;

begin
end;

Incidentally the above code, when compiled as a script, produces a hint that I believe is in error:

Hint: Overloaded method "Create" should be marked with the "overload" directive [line: 16, column: 5]

Here's the DFM format text of the TdwsUnit containing the declarations. You can paste this directly onto a form or datamodule):

#!
object dwsUnitConstructorVirtualOverload: TdwsUnit
  Classes = <
    item
      Name = 'TBase'
      Constructors = <
        item
          Name = 'Create'
          Attributes = [maVirtual, maAbstract]
        end>
    end
    item
      Name = 'TDerived'
      Ancestor = 'TBase'
      Constructors = <
        item
          Name = 'Create'
          Overloaded = True
          Attributes = [maVirtual, maOverride]
        end
        item
          Name = 'Create'
          Parameters = <
            item
              Name = 'Value'
              DataType = 'boolean'
            end>
          Overloaded = True
        end>
    end
    item
      Name = 'TProblem'
      Ancestor = 'TDerived'
      Constructors = <
        item
          Name = 'Create'
          Attributes = [maVirtual, maOverride]
        end>
    end>
  UnitName = 'Test'
end

Comments (2)

  1. Eric Grange repo owner

    Fixed Issue #81 + tests

    The "overload" keyword is essentially for humans, so it is hinted when missing by the compiler so that the code can be made more explicit. A future compiler option could be added to make "overload" unnecessary everywhere (test cases will have to be added/adapted then).

    → <<cset 685ccc936755>>

  2. Log in to comment