Cannot call generic routine with generic type
Original Reporter info from Mantis: sysrpl
-
Reporter name: Anthony Walter
Original Reporter info from Mantis: sysrpl
- Reporter name: Anthony Walter
Description:
With the introduction of generic routines to FPC trunk, you currently cannot call a generic subroutine with a generic type T.
Steps to reproduce:
In this example, Test&LtPos;T> cannot reuse T in its call to Min&LtPos;T>. This line should be legal "Value := Min&LtPos;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.
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.
Additional information:
Generic routines announcement:
November 21, 2015
http://www.mail-archive.com/fpc-pascal@lists.freepascal.org/msg40610.html
Mantis conversion info:
- Mantis ID: 29080
- OS: Ubuntu
- OS Build: 14.04 64bit
- Build: trunk
- Platform: Linux
- Version: 3.1.1
- Fixed in version: 3.1.1
- Fixed in revision: 33275 (#e9fab1bf)