Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2020-12

Generic instantiations as result types of procedural types

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Unknown author

The patch http://hg.blaise.ru/public/fpc/rev/544a934d262e (attached) fixes the following: -------8<-------
{$Mode Delphi}

type 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) : G<T> of object;
	function Foo(const X: T): G<T>;
end;
function G<T>.Foo(const X: T): G<T>;
begin
	result := G<T>.Create;
	result.X := X
end;
begin
	G<Integer>.F := G<Integer>.Create.Foo;
	writeln( G<Integer>.F(42).X = 42 );
end.
-------8<-------
βþ

Reply by email

Sven Barth
to Unknown author
Blaise--- wrote 25 lines
The patch http://hg.blaise.ru/public/fpc/rev/544a934d262e (attached) fixes the following: -------8<------- {$Mode Delphi} type 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) : G<T> of object;     function Foo(const X: T): G<T>; end; function G<T>.Foo(const X: T): G<T>; begin     result := G<T>.Create;     result.X := X end; begin     G<Integer>.F := G<Integer>.Create.Foo;     writeln( G<Integer>.F(42).X = 42 ); end. -------8<-------

Applied in r47795.

Regards,
Sven

Reply by email