<div dir="ltr"><div><div><div><div><div><div><div><div><div><div><div>Hello,<br><br></div><div>Fpc version: 3.0 (the one provided by Lazarus).<br></div><div><br></div>Please confirm if this is a bug regarding operator overloading and type specialization. It is a quite difficult to explain, but i will try.<br><br><br></div>Consider this unit<br><br></div>=== CODE ===<br><br>unit MyRecordDefinitionA;<br><br>{$mode delphi}<br><br>interface<br><br>type<br>  TMyRecord<T> = record<br>  public<br>    FValue: T;<br>    class operator Add(A,B: TMyRecord<T>): TMyRecord<T>;<br>  end;<br><br>implementation<br><br>class operator TMyRecord<T>.Add(A,B: TMyRecord<T>): TMyRecord<T>;<br>begin<br>  Result.FValue := A.FValue + B.FValue;<br>end;<br><br>end.<br><br></div>=== END ===<br><br></div>The unit above defines a generic type named TMyRecord with the arithmetic operator overloaded Add. This type is supposed to be specialized with a type parameter that supports the add operation (e.g Integer types).<br><br></div><br></div>=== CODE ===<br><br>unit MyRecordDefinitionB;<br><br>{$mode delphi}<br><br>interface<br><br>type<br>  TMyRecord<T> = record<br>  public<br>    FValue: T;<br>    class operator LogicalAnd(A: TMyRecord<T>; B: Boolean): TMyRecord<T>;<br>  end;<br><br>implementation<br><br>class operator TMyRecord<T>.LogicalAnd(A: TMyRecord<T>; B: Boolean): TMyRecord<T>;<br>begin<br>  Result.FValue := A.FValue and B;<br>end;<br><br>end.<br><br></div>=== END ===<br><br><br>The unit above defines a generic type named TMyRecord too, but with the logical operator overloading And. This type is supposed to be specialized with a type parameter that supports the logical and operation (e.g Boolean types).<br><br></div><br>=== CODE ===<br></div><br>unit MyRecordSpecialization;<br><br>{$mode delphi}<br><br>interface<br><br>uses<br>  MyRecordDefinitionA, MyRecordDefinitionB;<br><br>type<br>  TMyIntegerRecord = MyRecordDefinitionA.TMyRecord<Integer>;<br>  TMyBooleanRecord = MyRecordDefinitionB.TMyRecord<Boolean>;<br><br>implementation<br><br>end.  <br><br></div><br>=== END ===<br><div><div><div><div><br><br></div><div>The unit above defines two specialized types based on the generic type TMyRecord defined in the units MyRecordDefinitionA and MyRecordDefinitionB. <br><br>When i try to compile MyRecordSpecialization, i get this error: "Operator is not overloaded: LongInt and Boolean".<br><br></div><div>It seems the compiler treats the type MyRecordDefinitionA.TMyRecord and MyRecordDefinitionB.TMyRecord as being the same type. So, the compiler try to apply the logical operator and of  MyRecordDefinitionB.TMyRecord in the integer specialization of the type MyRecordDefinitionA.TMyRecord.<br><br></div><div>Regards  </div></div></div></div></div>