View Issue Details

IDProjectCategoryView StatusLast Update
0037264FPCCompilerpublic2020-06-27 14:49
Reporterdmz73 Assigned To 
PrioritynormalSeverityminorReproducibilityalways
Status confirmedResolutionopen 
Platformx86_64OSWindows 
Product Version3.2.0 
Summary0037264: Syntax error when using logical operator with generic boolean functions
DescriptionWhen generic function that returns boolean result is used in another generic function inside IF statement with logical operator (OR/AND) the compiler reports an error.
If logical operators is not used then compiler works OK.
Steps To Reproduceprogram Project1;

{$mode delphi}

type

  { TRec1 }

  TRec1<T> = record
    class function IsV1: boolean; static;
    class function IsV2: boolean; static;
  end;

  { TRec2 }

  TRec2<T> = record
    function Test: boolean;
  end;

{ TRec1 }

class function TRec1<T>.IsV1: boolean;
begin
  result := true;
end;

class function TRec1<T>.IsV2: boolean;
begin
  result := true;
end;

{ TRec2 }

function TRec2<T>.Test: boolean;
begin
  // this compiles
  if TRec1<T>.IsV1 then result := true
  else if TRec1<T>.IsV2 then result := true
  else result := false;

  // this reports an error
  if TRec1<T>.IsV1 or TRec1<T>.IsV2 then result := true
  else result := false;
end;

begin

end.
Tagsgenerics
Fixed in Revision
FPCOldBugId
FPCTarget-
Attached Files

Activities

Sven Barth

2020-06-26 10:24

manager   ~0123598

This falls under the category of "complex expressions with generics in mode Delphi are not supported currently".

As a workaround you can locally specialize the TRec<>:

function TRec2<T>.Test: boolean;
type
  TMyRec = TRec<T>;
begin
  if TMyRec.IsV1 or TMyRec.IsV2 then result := true
  else result := false;
end;

Serge Anvarov

2020-06-27 14:49

reporter   ~0123617

Or use parenthesis: Result := (TRec1<T>.IsV1) or (TRec1<T>.IsV2);

Issue History

Date Modified Username Field Change
2020-06-26 08:37 dmz73 New Issue
2020-06-26 09:01 Cyrax Tag Attached: generics
2020-06-26 10:24 Sven Barth Status new => confirmed
2020-06-26 10:24 Sven Barth FPCTarget => -
2020-06-26 10:24 Sven Barth Note Added: 0123598
2020-06-27 14:49 Serge Anvarov Note Added: 0123617