View Issue Details

IDProjectCategoryView StatusLast Update
0038145FPCCompilerpublic2020-11-29 17:43
Reporteravk Assigned ToSven Barth  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
PlatformanyOSany 
Product Version3.3.1 
Fixed in Version3.3.1 
Summary0038145: Generic specialization problem
DescriptionGeneric 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 ReproduceTry to compile the provided examples.
Tagsgenerics
Fixed in Revision47634
FPCOldBugId
FPCTarget-
Attached Files

Activities

Sven Barth

2020-11-28 17:02

manager   ~0127243

Please note that this is not specific to generics: this will fail for any assignment operator to a ShortString with a specified length <> 255.

Considering that Delphi allows such code I've raised the issue on Core.

Sven Barth

2020-11-29 16:48

manager   ~0127256

Please test and close if okay.

avk

2020-11-29 17:43

reporter   ~0127258

Thank you very much!

Issue History

Date Modified Username Field Change
2020-11-28 09:23 avk New Issue
2020-11-28 09:24 avk Tag Attached: generics
2020-11-28 17:02 Sven Barth Note Added: 0127243
2020-11-29 16:48 Sven Barth Assigned To => Sven Barth
2020-11-29 16:48 Sven Barth Status new => resolved
2020-11-29 16:48 Sven Barth Resolution open => fixed
2020-11-29 16:48 Sven Barth Fixed in Version => 3.3.1
2020-11-29 16:48 Sven Barth Fixed in Revision => 47634
2020-11-29 16:48 Sven Barth FPCTarget => -
2020-11-29 16:48 Sven Barth Note Added: 0127256
2020-11-29 17:43 avk Status resolved => closed
2020-11-29 17:43 avk Note Added: 0127258