[fpc-pascal] Generic operator overload problem
Sven Barth
pascaldragon at googlemail.com
Fri Nov 8 23:32:27 CET 2019
Am 02.11.2019 um 15:01 schrieb Ryan Joseph via fpc-pascal:
> Is this a bug or did I do something wrong? The minus operator overload seems to be getting confused and I get a "Can't determine which overloaded function to call" error as a result.
>
> {$mode objfpc}
> {$modeswitch advancedrecords}
>
> program generic_vector;
> uses
> Math;
>
> type
> generic TVec2<TScalar> = record
> x, y: TScalar;
> function Magnitude: TScalar;
> function Distance (vec: TVec2): TScalar;
> class operator - (left, right: TVec2): TVec2;
> class operator - (left: TVec2; right: TScalar): TVec2;
> end;
> TVec2f = specialize TVec2<Float>;
> TVec2i = specialize TVec2<Integer>;
>
> function TVec2.Magnitude: TScalar;
> begin
> result := (x ** 2) + (y ** 2);
> end;
>
> function TVec2.Distance (vec: TVec2): TScalar;
> begin
> // ----->>> ERROR: Can't determine which overloaded function to call
> result := (self - vec).Magnitude;
> end;
>
> class operator TVec2.- (left, right: TVec2): TVec2;
> begin
> result.x := left.x - right.x;
> result.y := left.y - right.y;
> end;
>
> class operator TVec2.- (left: TVec2; right: TScalar): TVec2;
> begin
> result.x := left.x - right;
> result.y := left.y - right;
> end;
>
> begin
> end.
This indeed appears to be a bug, but fixing it leads to some compilation
problems in Generics.Collections that need to be solved as well. So
please report this as a bug so that I don't forget it.
Regards,
Sven
More information about the fpc-pascal
mailing list