Hi, I am trying to learn freepascal generics and I think that I have found 2 bugs.
Tested with FPC 2.4.4 Linux x86 ================== = BUG 1 - with SizeOf = ================== program SizeOfBug; {$mode objfpc}{$H+} type generic TGen<_T> = class(TObject) private FField: _T; public constructor Create(Val: _T); function Bug: Integer; end; {--- TGen.Create ---} constructor TGen.Create(Val: _T); begin inherited Create; FField := Val; end; {--- TGen.Bug ---} function TGen.Bug : Integer; begin Result := 100000 div SizeOf(_T); // *** DIVISION BY ZERO *** // THE FOLLOWING CODE IS OK ! // // var // S: Integer; // begin // S := SizeOf(_T); // Result := 100000 div S; end; type TGenInt = specialize TGen<Integer>; var V: TGenInt; begin V.Create(589); WriteLn('V.Bug = ', V.Bug); V.Free; end. ================== = BUG 2 - with WriteLn = ================== program WriteLnBug; {$mode objfpc}{$H+} type generic TGen<_T> = class(TObject) private FField: _T; public constructor Create(Val: _T); procedure Bug; end; {--- TGen.Create ---} constructor TGen.Create(Val: _T); begin inherited Create; FField := Val; end; {--- TGen.Bug ---} procedure TGen.Bug; begin WriteLn('FField = ', FField); // *** CAN'T READ OR WRITE VARIABLES OF THIS TYPE *** end; type TGenInt = specialize TGen<Integer>; var V: TGenInt; begin V.Create(589); V.Bug; V.Free; end. _______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal