<div dir="ltr"><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div>Hello,<br><br></div>Fpc version: 3.0 (the same included with lazarus 1.6).<br><br><br></div>Please confirm if it is a bug: <br><br></div>If i declare a generic record with overloaded add operation, i need to specialize the type in the same unit for the compiler recognize the overloading.<br><br></div>=== Code === <br><br></div>unit MyRecordDefinition;<br><br></div><div>{$mode delphi}<br></div><div><br></div>interface<br><br></div>type<br></div>  TMyRecord<T> = record<br></div><div>     class operator Add(A,B: TMyRecord<T>): TMyRecord<T>;<br></div>  end;<br><br></div>implementation<br><br> class operator TMyRecord<T>.Add(A,B: TMyRecord<T>): TMyRecord<T>;<br></div>begin<br>////<br></div>end;<br><br></div><div>end.<br></div><div><br>......................<br><br><br></div>Unit MyRecordSpecialization;<br><br>{$mode delphi}<br><br></div><div>interface<br></div><div><br></div>uses<br>  MyRecordDefinition;<br><br></div>type<br></div>  TInteger = TMyRecord<Integer>;<br><br></div>implementation<br><br>procedure TestIfCompiles;<br>var<br>  N1, N2: NullableInteger;<br>begin<br>  N1 := N2 + N2; // DOESN'T COMPILE: Operator is not overloaded: TMyRecord + TMyRecord<br>end;<br><br><br></div>end.<br><div><div><div><div>   <br><div><div><div><div><div><br></div><div>==== END ====<br><br><br></div><div><br>To get this code compiled, i need to move the specialized type TInteger to the same unit where the generic type TMyRecord is declared.<br><br><br></div><div><br>==== code === <br></div><div><br>unit MyRecordDefinition;<br><br><div>{$mode delphi}<br></div><div><br></div>interface<br><br>type<br>  TMyRecord<T> = record<br><div>     class operator Add(A,B: TMyRecord<T>): TMyRecord<T>;<br></div>  end;<br><br>  TInteger = TMyRecord<Integer>;<br><br>implementation<br><br> class operator TMyRecord<T>.Add(A,B: TMyRecord<T>): TMyRecord<T>;<br>begin<br>////<br>end;<br><br><div>end.<br></div><div><br>......................<br><br><br></div>Unit MyRecordSpecialization;<br><br>{$mode delphi}<br><br><div>interface<br></div><div><br></div>uses<br>  MyRecordDefinition;<br><br>implementation<br><br>procedure TestIfCompiles;<br>var<br>  N1, N2: NullableInteger;<br>begin<br>  N1 := N2 + N2; // DOESN'T COMPILE: Operator is not overloaded: TMyRecord + TMyRecord<br>end;<br><br><br>end.<br><br><br></div><div>=== END ====<br></div><div><br><br></div><div>Best regards<br></div><div><br></div><div><br></div></div></div></div></div></div></div></div></div></div>