On Tue, 9 May 2023, Thomas Kurz via fpc-pascal wrote:
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?
This is intended behaviour since declarations in helpers always take
precedence over the methods in the class/record.
Try to add overload; to the constructor in the helper. This is a hint to the
compiler that it should look for other methods.
Michael.
_______________________________________________
fpc-pascal maillist - [email protected]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal