View Issue Details

IDProjectCategoryView StatusLast Update
0036180FPCFCLpublic2019-10-19 16:21
ReporterRyan JosephAssigned ToMichael Van Canneyt 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Product Version3.3.1Product Build 
Target VersionFixed in Version3.3.1 
Summary0036180: fcl-passrc record class operator fails
Description{$mode objfpc}
{$modeswitch advancedrecords}

program bugs;

type
  TMyRecord = record
    class operator = (a, b: TMyRecordA): boolean;
  end;

// EParserError: Expected "procedure" at token "operator"
class operator TMyRecord.= (a, b: TMyRecordA): boolean;
begin
  result := (@a = @b);
end;

begin
end.
Steps To ReproduceUse test.pas to parse the bug file.
TagsNo tags attached.
Fixed in Revision43229
FPCOldBugId
FPCTarget3.2.0
Attached Files
  • test.pas (1,041 bytes)
    {$mode objfpc}
    {$H+}
    
    program test;
    uses
      PasTree, PParser;
    
    type
      TSimpleEngine = class(TPasTreeContainer)
      public
        function CreateElement(AClass: TPTreeElement; const AName: String; AParent: TPasElement; AVisibility: TPasMemberVisibility; const ASourceFilename: String; ASourceLinenumber: Integer): TPasElement; override;
        function FindElement(const AName: String): TPasElement; override;
       end;
    
    function TSimpleEngine.FindElement(const AName: String): TPasElement;
    begin
      result := nil;
    end;
    
    function TSimpleEngine.CreateElement(AClass: TPTreeElement; const AName: String; AParent: TPasElement; AVisibility: TPasMemberVisibility; const ASourceFilename: String; ASourceLinenumber: Integer): TPasElement;
    begin
      result := AClass.Create(AName, AParent);
      result.Visibility := AVisibility;
      result.SourceFilename := ASourceFilename;
      result.SourceLinenumber := ASourceLinenumber;
    end;
    
    var
      engine: TSimpleEngine;
    begin
      engine := TSimpleEngine.Create;
      ParseSource(engine, '-Mobjfpc bug_2.pas', 'darwin', 'x86_64'); 
    end.
    test.pas (1,041 bytes)
  • bug_2.pas (246 bytes)
    {$mode objfpc}
    {$modeswitch advancedrecords}
    
    program bugs;
    
    type
      TMyRecord = record
        class operator = (a, b: TMyRecordA): boolean;
      end;
    
    class operator TMyRecord.= (a, b: TMyRecordA): boolean;
    begin
      result := (@a = @b);
    end;
    
    begin
    end.
    bug_2.pas (246 bytes)

Activities

Ryan Joseph

2019-10-14 16:31

reporter  

test.pas (1,041 bytes)
{$mode objfpc}
{$H+}

program test;
uses
  PasTree, PParser;

type
  TSimpleEngine = class(TPasTreeContainer)
  public
    function CreateElement(AClass: TPTreeElement; const AName: String; AParent: TPasElement; AVisibility: TPasMemberVisibility; const ASourceFilename: String; ASourceLinenumber: Integer): TPasElement; override;
    function FindElement(const AName: String): TPasElement; override;
   end;

function TSimpleEngine.FindElement(const AName: String): TPasElement;
begin
  result := nil;
end;

function TSimpleEngine.CreateElement(AClass: TPTreeElement; const AName: String; AParent: TPasElement; AVisibility: TPasMemberVisibility; const ASourceFilename: String; ASourceLinenumber: Integer): TPasElement;
begin
  result := AClass.Create(AName, AParent);
  result.Visibility := AVisibility;
  result.SourceFilename := ASourceFilename;
  result.SourceLinenumber := ASourceLinenumber;
end;

var
  engine: TSimpleEngine;
begin
  engine := TSimpleEngine.Create;
  ParseSource(engine, '-Mobjfpc bug_2.pas', 'darwin', 'x86_64'); 
end.
test.pas (1,041 bytes)
bug_2.pas (246 bytes)
{$mode objfpc}
{$modeswitch advancedrecords}

program bugs;

type
  TMyRecord = record
    class operator = (a, b: TMyRecordA): boolean;
  end;

class operator TMyRecord.= (a, b: TMyRecordA): boolean;
begin
  result := (@a = @b);
end;

begin
end.
bug_2.pas (246 bytes)

jamie philbrook

2019-10-14 16:49

reporter   ~0118590

type
   TMyRecord = record
     class operator = (a, b: TMyRecord): boolean;
   end;
   // EParserError: Expected "procedure" at token "operator"
    class operator TMyRecord.= (a, b: TMyRecord): boolean; // remove the "A" at the end..
    begin
      result := (@a = @b);
    end;

It compiles fine for me on 3.0.4 and I am sure it works just as well when corrected on 3.3.x
Personally I don't see the gain here? the compiler already has a Record compare I use it quite often.

 If A = B then … etc.

 But here you are trying to change it to testing for addresses which the compile still can do that now..

 Don't pay any attention to me, I am just a backyard software mechanic

Ryan Joseph

2019-10-14 17:18

reporter   ~0118592

Sorry, this is for the fcl-passrc parser package, not the compiler. Oops I left the "A" in there by accident. Just ignore this bug report since it's for the developer of the fcl-passrc package. We discussed this on the mail list yesterday.

jamie philbrook

2019-10-14 17:30

reporter   ~0118593

Ok, then maybe you should close it?

Ryan Joseph

2019-10-14 17:52

reporter   ~0118595

No, I mean the issue should be assigned to Michael Van Canneyt because it's regarding his parser. It's not a compiler bug.

Michael Van Canneyt

2019-10-19 16:11

administrator   ~0118697

Fixed, please test and close if OK.

Ryan Joseph

2019-10-19 16:21

reporter   ~0118699

Fixed, thanks again Michael.

Issue History

Date Modified Username Field Change
2019-10-14 16:31 Ryan Joseph New Issue
2019-10-14 16:31 Ryan Joseph File Added: test.pas
2019-10-14 16:31 Ryan Joseph File Added: bug_2.pas
2019-10-14 16:49 jamie philbrook Note Added: 0118590
2019-10-14 17:18 Ryan Joseph Note Added: 0118592
2019-10-14 17:30 jamie philbrook Note Added: 0118593
2019-10-14 17:52 Ryan Joseph Note Added: 0118595
2019-10-19 16:11 Michael Van Canneyt Assigned To => Michael Van Canneyt
2019-10-19 16:11 Michael Van Canneyt Status new => resolved
2019-10-19 16:11 Michael Van Canneyt Resolution open => fixed
2019-10-19 16:11 Michael Van Canneyt Fixed in Version => 3.3.1
2019-10-19 16:11 Michael Van Canneyt Fixed in Revision => 43229
2019-10-19 16:11 Michael Van Canneyt FPCTarget => 3.2.0
2019-10-19 16:11 Michael Van Canneyt Note Added: 0118697
2019-10-19 16:21 Ryan Joseph Status resolved => closed
2019-10-19 16:21 Ryan Joseph Note Added: 0118699