diff --git a/.gitattributes b/.gitattributes index 5c16b5c80a..0874aa939d 100644 --- a/.gitattributes +++ b/.gitattributes @@ -6600,6 +6600,7 @@ tests/test/tvarset1.pp svneol=native#text/plain tests/test/twide1.pp svneol=native#text/plain tests/test/twide2.pp svneol=native#text/plain tests/test/uabstrcl.pp svneol=native#text/plain +tests/test/ugeneric10.pp svneol=native#text/plain tests/test/ugeneric3.pp svneol=native#text/plain tests/test/ugeneric4.pp svneol=native#text/plain tests/test/uimpluni1.pp svneol=native#text/plain diff --git a/tests/test/tgeneric10.pp b/tests/test/tgeneric10.pp index 7c403e2b24..7578c74e09 100644 --- a/tests/test/tgeneric10.pp +++ b/tests/test/tgeneric10.pp @@ -1,37 +1,23 @@ {$mode objfpc} -type - generic TList<_T>=class(TObject) - type public - TCompareFunc = function(const Item1, Item2: _T): Integer; - var public - data : _T; - compare : TCompareFunc; - procedure Add(item: _T); - end; +uses + ugeneric10; -procedure TList.Add(item: _T); -begin - data:=item; - if compare(data, 20) <= 0 then - halt(1); -end; +type + TMyIntList = specialize TList; function CompareInt(Item1, Item2: Integer): Integer; begin Result := Item2 - Item1; end; -type - TMyIntList = specialize TList; - var ilist : TMyIntList; someInt : integer; begin someInt:=10; ilist := TMyIntList.Create; - ilist.compare := ilist.TCompareFunc(@CompareInt); ilist.add(someInt); + ilist.sort(ilist.TCompareFunc(@CompareInt)); writeln('ok'); end. diff --git a/tests/test/tgeneric11.pp b/tests/test/tgeneric11.pp index 5991c5ea95..4f35f1502b 100644 --- a/tests/test/tgeneric11.pp +++ b/tests/test/tgeneric11.pp @@ -2,12 +2,10 @@ type generic TList<_T>=class(TObject) - type protected - TSelf = specialize TList<_T>; var public data : _T; procedure Add(item: _T); - procedure Assign(Source: TSelf); + procedure Assign(Source: TList); end; procedure TList.Add(item: _T); @@ -15,7 +13,7 @@ begin data:=item; end; -procedure TList.Assign(Source: TSelf); +procedure TList.Assign(Source: TList); begin data:=Source.data; end; diff --git a/tests/test/ugeneric10.pp b/tests/test/ugeneric10.pp new file mode 100644 index 0000000000..7bfbdb1028 --- /dev/null +++ b/tests/test/ugeneric10.pp @@ -0,0 +1,30 @@ +unit ugeneric10; + +{$mode objfpc} + +interface + +type + generic TList<_T>=class(TObject) + type public + TCompareFunc = function(const Item1, Item2: _T): Integer; + var public + data : _T; + procedure Add(item: _T); + procedure Sort(compare: TCompareFunc); + end; + +implementation + +procedure TList.Add(item: _T); +begin + data:=item; +end; + +procedure TList.Sort(compare: TCompareFunc); +begin + if compare(data, 20) <= 0 then + halt(1); +end; + +end.