Generic specialization problem
Original Reporter info from Mantis: avk @avk959
-
Reporter name: avk
Original Reporter info from Mantis: avk @avk959
- Reporter name: avk
Description:
Generic cannot be specialized with a short string of non-standard length if it contains operators for casting to the type of a formal parameter.
program test;
{$mode delphi}
type
TMyWrap<T> = record
Value: T;
class operator Explicit(const w: TMyWrap<T>): T;
class operator Implicit(const w: TMyWrap<T>): T;
end;
class operator TMyWrap<T>.Explicit(const w: TMyWrap<T>): T;
begin
Result := w.Value;
end;
class operator TMyWrap<T>.Implicit(const w: TMyWrap<T>): T;
begin
Result := w.Value;
end;
type
//TString = string[255]; //compiles
TString = string[254]; //not compiles
var
MySpec: TMyWrap<TString>;
begin
end.
and another mode:
program test;
{$mode objfpc}{$modeswitch advancedrecords}
type
generic TMyWrap<T> = record
Value: T;
class operator Explicit(const w: TMyWrap): T;
class operator :=(const w: TMyWrap): T;
end;
class operator TMyWrap.Explicit(const w: TMyWrap): T;
begin
Result := w.Value;
end;
class operator TMyWrap.:=(const w: TMyWrap): T;
begin
Result := w.Value;
end;
type
//TString = string[255]; //compiles
TString = string[254]; //not compiles
var
MySpec: specialize TMyWrap<TString>;
begin
end.
Steps to reproduce:
Try to compile the provided examples.
Mantis conversion info:
- Mantis ID: 38145
- OS: any
- OS Build: any
- Build: 47607
- Platform: any
- Version: 3.3.1
- Fixed in version: 3.3.1
- Fixed in revision: 47634 (#3597696e)