[fpc-pascal] Record Constructors which differ in parameter lists

Thomas Kurz fpc.2021 at t-net.ruhr
Tue May 9 12:56:19 CEST 2023


Hello,

let's take the following example:

program Project1;

{$MODE OBJFPC}
{$MODESWITCH ADVANCEDRECORDS}
{$MODESWITCH TYPEHELPERS}

type TVec3f = record
  x, y, z: Double;
  constructor Create (a1, a2, a3: Double);
end;

type TSomething = type TVec3f;

type TSomethingHelper = type helper for TSomething
  constructor Create (a1, a2: Double);
end;

constructor TVec3f.Create (a1, a2, a3: Double);
begin
  Self.x := a1;
  Self.y := a2;
  Self.z := a3;
end;

constructor TSomethingHelper.Create (a1, a2: Double);
begin
  Self.x := a1;
  Self.y := a2;
  Self.z := 1 - a1 - a2;
end;

var f: TVec3f;

begin
  f := TVec3f.Create (0.0, 0.0, 0.0);     // <-- error here
end.


I get the error:
project1.lpr(35,37) Error: Wrong number of parameters specified for call to "Create"
project1.lpr(25,30) Error: Found declaration: constructor Create(Double;Double);

So, obviously, FPC tries to apply the helper of TSomething (which should be decoupled from TVec3f because of the "type TVec3f" declaration) to TVec3f which hasn't defined any constructor with 2 parameters.

Is this intended behavior or should I report it as a bug?

Versions used:
Lazarus 2.3.0 (rev main-2_3-3525-g9208f17734) FPC 3.3.1 i386-win32-win32/win64
(FPC is not the most recent build, it's about 2~3 weeks old)



More information about the fpc-pascal mailing list