View Issue Details

IDProjectCategoryView StatusLast Update
0037729FPCCompilerpublic2020-09-10 15:45
ReporterAkira1364 Assigned To 
PrioritynormalSeverityminorReproducibilityalways
Status newResolutionopen 
Platformx86_64OSWindows 
Product Version3.3.1 
Summary0037729: Incorrectly using a type alias where a field name should be while initializing an advanced record is not handled properly
DescriptionOn top of that, both {$mode ObjFPC} and {$mode Delphi} result in different outcomes, neither of which are the ideal one.

Example of the bug in {$mode ObjFPC}:

program ObjFPCBugExample;

{$mode ObjFPC}
{$modeswitch AdvancedRecords}

type
  TBugExample = record
  type
    IsNotAField = PtrInt;
    IsAlsoNotAField = Double;
  public
    IsAField: array[0..2] of PtrInt;
    IsAlsoAField: array[0..3] of PtrInt;
  end;

const Bug: TBugExample = (
  IsNotAField: (1, 2, 3);
  IsAlsoNotAField: (1, 2, 3, 4)
);

begin
end.

Resulting in the following compiler output:

ObjFPCBugExample.pas(17,16) Error: Some fields coming before "IsNotAField" were not initialized
ObjFPCBugExample.pas(17,25) Fatal: Syntax error, "identifier" expected but ";" found
Fatal: Compilation aborted

Example of the bug in mode {$Delphi}:

program DelphiBugExample;

{$mode Delphi}

type
  TBugExample = record
  type
    IsNotAField = PtrInt;
    IsAlsoNotAField = Double;
  public
    IsAField: array[0..2] of PtrInt;
    IsAlsoAField: array[0..3] of PtrInt;
  end;

const Bug: TBugExample = (
  IsNotAField: (1, 2, 3);
  IsAlsoNotAField: (1, 2, 3, 4)
);

begin
end.

Resulting in the following (even worse) compiler output:

DelphiBugExample.pas(16,16) Warning: Some fields coming before "IsNotAField" were not initialized
DelphiBugExample.pas(16,16) Error: Compilation raised exception internally
Fatal: Compilation aborted
An unhandled exception occurred at $00000000005ED95C:
EAccessViolation: Access violation
  $00000000005ED95C

In both modes, I believe the correct output would actually be this:

BugExample.pas(17,6) Error: Unknown record field identifier "IsNotAField"
BugExample.pas(17,15) Fatal: Syntax error, "identifier" expected but ";" found
Fatal: Compilation aborted
Steps To ReproduceAttempt to compile the provided examples.
TagsNo tags attached.
Fixed in Revision
FPCOldBugId
FPCTarget
Attached Files

Activities

Akira1364

2020-09-10 15:43

reporter  

ObjFPCBugExample.pas (358 bytes)   
program ObjFPCBugExample;

{$mode ObjFPC}
{$modeswitch AdvancedRecords}

type
  TBugExample = record
  type
    IsNotAField = PtrInt;
    IsAlsoNotAField = Double;
  public
    IsAField: array[0..2] of PtrInt;
    IsAlsoAField: array[0..3] of PtrInt;
  end;

const Bug: TBugExample = (
  IsNotAField: (1, 2, 3);
  IsAlsoNotAField: (1, 2, 3, 4)
);

begin
end.
ObjFPCBugExample.pas (358 bytes)   
DelphiBugExample.pas (328 bytes)   
program DelphiBugExample;

{$mode Delphi}

type
  TBugExample = record
  type
    IsNotAField = PtrInt;
    IsAlsoNotAField = Double;
  public
    IsAField: array[0..2] of PtrInt;
    IsAlsoAField: array[0..3] of PtrInt;
  end;

const Bug: TBugExample = (
  IsNotAField: (1, 2, 3);
  IsAlsoNotAField: (1, 2, 3, 4)
);

begin
end.
DelphiBugExample.pas (328 bytes)   

Issue History

Date Modified Username Field Change
2020-09-10 15:43 Akira1364 New Issue
2020-09-10 15:43 Akira1364 File Added: ObjFPCBugExample.pas
2020-09-10 15:43 Akira1364 File Added: DelphiBugExample.pas