Generic "advanced records" cannot have more than one of the same class operator overload if the parameters are fully generic
Original Reporter info from Mantis: Akira1364
-
Reporter name:
Original Reporter info from Mantis: Akira1364
- Reporter name:
Description:
This is in contrast with non-operator generic member functions and procedures within generic advanced records, where it is no issue to declare two methods with the same name and the same number of parameters.
(As far as I can tell, the actual "overload" keyword has no effect on generics whatsoever in any case, also.)
Steps to reproduce:
Attempt to compile the following program:
program Test;
{$mode ObjFPC}
{$modeswitch AdvancedRecords}
type
generic TGenRec<T1, T2> = record
A: T1;
B: T2;
function FuncA(const T: T1): T1;
function FuncA(const T: T2): T2;
class operator :=(constref Rec: TGenRec): T1;
class operator :=(constref Rec: TGenRec): T2;
end;
function TGenRec.FuncA(const T: T1): T1;
begin
Result := T;
end;
function TGenRec.FuncA(const T: T2): T2;
begin
Result := T;
end;
class operator TGenRec.:=(constref Rec: TGenRec): T1;
begin
Result := Rec.A;
end;
class operator TGenRec.:=(constref Rec: TGenRec): T2;
begin
Result := Rec.B;
end;
begin
end.
You should receive no less than five error messages:
Error: Function is already declared Public/Forward "operator :=(constref TGenRec$2):&LtPos;undefined type>; Static;"
Error: overloaded functions have the same parameter list
Error: Found declaration: operator :=(constref TGenRec$2):&LtPos;undefined type>; Static;
Error: function header doesn't match any method of this class "operator :=(constref TGenRec$2):&LtPos;undefined type>; Static;"
Error: Found declaration: operator :=(constref TGenRec$2):&LtPos;undefined type>; Static;
Meanwhile the compiler has no issue whatsoever with the dual declarations of "FuncA", neither of which have any concrete type parameters.
Mantis conversion info:
- Mantis ID: 34497
- OS: Windows
- OS Build: 10
- Build: 40178
- Platform: x86_64
- Version: 3.3.1
- Monitored by: » Akira1364 (Akira1364)