[fpc-pascal] Feature announcement: Generic functions, procedures and methods
Anthony Walter
sysrpl at gmail.com
Tue Nov 24 14:25:47 CET 2015
Sven, it would seem you cannot currently cannot pass a generic T to resolve
the type of another generic subroutine.
In this example, Test<T> cannot reuse T in its call to Min<T>. I believe
this line should be legal "Value := Min<T>(A, B);" (see the code below for
context)
Currently when you try to compile the unit GenericTest you'll receive a
compiler error on line marked below. Would you like me to enter this into
issue into mantis?
unit GenericTest;
{$mode delphi}
interface
function Min<T>(const A, B: T): T;
function Max<T>(const A, B: T): T;
procedure Test<T>(const A, B: T);
implementation
function Min<T>(const A, B: T): T;
// Error on line below, GenericTest.pas(14,1) Error: Internal error
200301231
begin
if A > B then
Result := A
else
Result := B;
end;
function Max<T>(const A, B: T): T;
begin
if A > B then
Result := A
else
Result := B;
end;
procedure Test<T>(const A, B: T);
var
Value: T;
begin
// This should be legal
Value := Min<T>(A, B);
WriteLn('The Min<T> of values, ', A, ' and ', B, ' are: ', Value);
// As well as this
Value := Max<T>(A, B);
WriteLn('The Max<T> of values, ', A, ' and ', B, ' are: ', Value);
end;
end.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20151124/6fffab4f/attachment.html>
More information about the fpc-pascal
mailing list