fpc/tests/test/tgeneric107.pp
svenbarth f455d66a75 Merged revision(s) 47794-47795, 47826 from trunk:
* apply patch by Blaise.ru to allow record methods to be assigned to method variables as well (this is Delphi compatible)
+ added test
........
* apply patch by Blaise.ru to allow specializations for the result type of function and method variables
+ added tests
........
* fix for Mantis #38238: when creating a copy of a procdef for a procvar set the methodpointer flag also for methods of records
+ added test
........

git-svn-id: branches/fixes_3_2@48653 -
2021-02-11 21:30:38 +00:00

24 lines
581 B
ObjectPascal

program tgeneric107;
{$Mode ObjFpc}
type generic G<T> = class
var X: T;
// EXPECTED: gets compiled
// ACTUAL: 'Error: Generics without specialization cannot be used as a type for a variable'
class var F: function(const X: T) : specialize G<T> of object;
function Foo(const aX: T): specialize G<T>;
end;
function G.Foo(const aX: T): specialize G<T>;
begin
result := specialize G<T>.Create;
result.X := aX
end;
begin
specialize G<Integer>.F := @specialize G<Integer>.Create.Foo;
if specialize G<Integer>.F(42).X <> 42 then
halt(1);
end.