[fpc-devel] Generic instantiations as result types of procedural types

Blaise at blaise.ru Blaise at blaise.ru
Wed Dec 16 17:09:27 CET 2020


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<-------

-- 
βþ
-------------- next part --------------
# HG changeset patch
# User Blaise.ru
# Date 1608134554 -10800
! procvar_dec: allow generic instantiations as result types of procedural types

diff -r 0a8aff8d8273 -r 544a934d262e ptype.pas
--- a/ptype.pas	Wed Dec 16 16:38:50 2020 +0300
+++ b/ptype.pas	Wed Dec 16 19:02:34 2020 +0300
@@ -1587,7 +1587,7 @@
             if is_func then
               begin
                 consume(_COLON);
-                single_type(pd.returndef,[]);
+                single_type(pd.returndef,[stoAllowSpecialization]);
               end;
             if try_to_consume(_OF) then
               begin


More information about the fpc-devel mailing list