Incorrectly using a type alias where a field name should be while initializing an advanced record is not handled properly
Original Reporter info from Mantis: Akira1364
-
Reporter name:
Original Reporter info from Mantis: Akira1364
- Reporter name:
Description:
On 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 reproduce:
Attempt to compile the provided examples.
Mantis conversion info:
- Mantis ID: 37729
- OS: Windows
- OS Build: 10
- Build: 46827
- Platform: x86_64
- Version: 3.3.1
- Monitored by: » Akira1364 (Akira1364)