View Issue Details

IDProjectCategoryView StatusLast Update
0037806FPCCompilerpublic2020-09-25 17:21
Reporteravk Assigned ToSven Barth  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
PlatformanyOSany 
Product Version3.3.1 
Fixed in Version3.3.1 
Summary0037806: Include/Exclude intrinsics are not aware of generics.
DescriptionThis simple example does not compile:

program test;

{$mode delphi}

procedure TurnSetElem<TSet, TElem>(var aSet: TSet; aElem: TElem; aOn: Boolean);
begin
  if aOn then
    Include(aSet, aElem)
  else
    Exclude(aSet, aElem);
end;

type
  TElem = (One, Two, Three, Four, Five);
  TSet = set of TElem;

var
  s: TSet = [];

begin
  TurnSetElem<TSet, TElem>(s, Two, True);
  TurnSetElem<TSet, TElem>(s, Five, True);
  if not((Two in s) and (Five in s)) then
    WriteLn('does not work');
end.
Tagsgenerics
Fixed in Revision46953
FPCOldBugId
FPCTarget-
Attached Files

Activities

Michael Van Canneyt

2020-09-24 13:26

administrator   ~0125817

This is normal, the compiler has no way to know that the type template will contain a set when parsing your template.

It does not compile in delphi either.

So unless Delphi/we implement a "Enumerated" generic type constraint, I don't think this needs fixing.

Michael Van Canneyt

2020-09-24 13:27

administrator   ~0125818

Here the Delphi test program:

program testenums;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.SysUtils;

Type
  TA = Class(TObject)
    procedure TurnSetElem<TSet, TElem>(var aSet: TSet; aElem: TElem; aOn: Boolean);
  end;

procedure TA.TurnSetElem<TSet, TElem>(var aSet: TSet; aElem: TElem; aOn: Boolean);
begin
  if aOn then
    Include(aSet, aElem)
  else
    Exclude(aSet, aElem);
end;

type
  TElem = (One, Two, Three, Four, Five);
  TSet = set of TElem;

var
  s: TSet = [];
  A : TA;
begin
  A:=TA.Create;
  A.TurnSetElem<TSet, TElem>(s, Two, True);
  A.TurnSetElem<TSet, TElem>(s, Five, True);
  if not((Two in s) and (Five in s)) then
    WriteLn('does not work');
end.

Sven Barth

2020-09-24 14:13

manager   ~0125819

Last edited: 2020-09-24 14:13

View 2 revisions

@Michael: Please don't close generic bug reports when it was me who said that one should be opened. FPC does not need to behave as Delphi here, because we have a more template-like approach.

Michael Van Canneyt

2020-09-24 14:18

administrator   ~0125820

Sven, how should I know that you asked for this ?

But If you have an approach for this: so much the better.

avk

2020-09-24 16:41

reporter   ~0125821

I apologize for not mentioning the thread of the forum where this problem was discussed. It seemed obvious to me that the compiler should not make any assumptions about the generic parameters until the generic is specialized.

Sven Barth

2020-09-24 21:47

manager   ~0125830

@Michael: right, I forgot that you're not keeping close tabs on the forum like e.g. Marco and I are doing... Sorry, 'bout that...

Sven Barth

2020-09-25 16:14

manager   ~0125860

Please test and close if okay.

avk

2020-09-25 17:21

reporter   ~0125862

Thank you very much.

Issue History

Date Modified Username Field Change
2020-09-24 05:37 avk New Issue
2020-09-24 05:38 avk Tag Attached: generics
2020-09-24 13:26 Michael Van Canneyt Assigned To => Michael Van Canneyt
2020-09-24 13:26 Michael Van Canneyt Status new => resolved
2020-09-24 13:26 Michael Van Canneyt Resolution open => no change required
2020-09-24 13:26 Michael Van Canneyt FPCTarget => -
2020-09-24 13:26 Michael Van Canneyt Note Added: 0125817
2020-09-24 13:27 Michael Van Canneyt Note Added: 0125818
2020-09-24 14:13 Sven Barth Assigned To Michael Van Canneyt =>
2020-09-24 14:13 Sven Barth Status resolved => new
2020-09-24 14:13 Sven Barth Resolution no change required => open
2020-09-24 14:13 Sven Barth Note Added: 0125819
2020-09-24 14:13 Sven Barth Note Edited: 0125819 View Revisions
2020-09-24 14:18 Michael Van Canneyt Note Added: 0125820
2020-09-24 14:19 Michael Van Canneyt Assigned To => Sven Barth
2020-09-24 14:19 Michael Van Canneyt Status new => assigned
2020-09-24 16:41 avk Note Added: 0125821
2020-09-24 21:47 Sven Barth Note Added: 0125830
2020-09-25 16:14 Sven Barth Status assigned => resolved
2020-09-25 16:14 Sven Barth Resolution open => fixed
2020-09-25 16:14 Sven Barth Fixed in Version => 3.3.1
2020-09-25 16:14 Sven Barth Fixed in Revision => 46953
2020-09-25 16:14 Sven Barth Note Added: 0125860
2020-09-25 17:21 avk Status resolved => closed
2020-09-25 17:21 avk Note Added: 0125862