Using "String[ANumber]" as a generic specialization doesn't work, and fails in different specific ways based on {$mode}
Original Reporter info from Mantis: Akira1364
-
Reporter name:
Original Reporter info from Mantis: Akira1364
- Reporter name:
Description:
The {$mode ObjFPC} example shown below:
program Test;
{$mode ObjFPC}
{$modeswitch AdvancedRecords}
type
generic TBugRec<T> = record
strict private
FValue: T;
public
class function Make(const V: T): TBugRec; static; inline;
property Value: T read FValue;
end;
class function TBugRec.Make(const V: T): TBugRec;
begin
Result.FValue := V;
end;
begin
WriteLn(specialize TBugRec<String[4]>.Make('AAAA').Value);
end.
consistently gives the following compiler errors:
test.pas(21,39) Error: Type parameters of specializations of generics cannot reference the currently specialized type
test.pas(21,39) Error: Identifier not found "TBugRec$0"
test.pas(22,4) Fatal: There were 2 errors compiling module, stopping
Fatal: Compilation aborted
However, the {$mode Delphi} version, written like so:
program Test;
{$mode Delphi}
type
TBugRec<T> = record
strict private
FValue: T;
public
class function Make(const V: T): TBugRec<T>; static; inline;
property Value: T read FValue;
end;
class function TBugRec<T>.Make(const V: T): TBugRec<T>;
begin
Result.FValue := V;
end;
begin
WriteLn(TBugRec<String[4]>.Make('AAAA').Value);
end.
Gives no specific errors at all, and simply directly crashes the compiler:
test.pas(20,28) Error: Compilation raised exception internally
Fatal: Compilation aborted
An unhandled exception occurred at $00000000005A4BF5:
EAccessViolation: Access violation
$00000000005A4BF5
The results in both modes are certainly undesirable, I'd say.
Steps to reproduce:
Attempt to compile the provided "reproducer" programs.
Mantis conversion info:
- Mantis ID: 35717
- OS: Windows
- OS Build: 10
- Build: Trunk
- Platform: x86_64
- Version: 3.3.1
- Monitored by: » Akira1364 (Akira1364)