View Issue Details

IDProjectCategoryView StatusLast Update
0034055FPCCompilerpublic2018-10-21 20:49
Reporter440bxAssigned ToJonas Maebe 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
PlatformOSWindowsOS Version7
Product VersionProduct Build3.0.4 and 3.1.1 
Target VersionFixed in Version3.3.1 
Summary0034055: elements of arrays indexed by an enumerated type cannot be accessed using the enumerated type's elements
DescriptionAn array such as "somevar : array[enumerated_type] of sometype" cannot be indexed using the elements of the indexing enumerated type. Refer to the simple program below to see the problem (the example does not compile but, it should - Note: Delphi compiles it without complaint.) The compiler complains on case 3, it shouldn't. Case 3 is equivalent to cases 1 and 2.

{$MODE OBJFPC }

program EnumeratedTypeArrayIndexes;

const


  // ---------------------------------------------------------------------------
  // case 1. using literal constants - works fine

  test : array[0..1] of pwidechar = ('Dos signature',
                                     'Offset to new executable');

  a : pwidechar = @test[0]; // it really wants address of



  // ---------------------------------------------------------------------------
  // case 2. using named constants - works fine

  _Dos_Signature = 0;
  _Dos_OffsetToNewExecutable = 1;

  DosFieldLabelsA : array[_Dos_Signature.._Dos_OffsetToNewExecutable]
                        of pwidechar =
  (
    'DOS signature',
    'offset to new executable'
  );

  b : pwidechar = @DosFieldLabelsA[_Dos_Signature];



  // ---------------------------------------------------------------------------
  // case 3. using enumerated type constants (fully equivalent to case 2.)
  //
  // - should work but does not.

type
  TDOS_FIELDNAMES = (
                      Dos_Signature, // ord = 0
                      Dos_OffsetToNewExecutable // ord = 1
                    );



const
  DosFieldLabelsB : array[TDOS_FIELDNAMES]
                        of pwidechar =
  (
    'DOS signature',
    'offset to new executable'
  );

  d : pwidechar = @DosFieldLabelsB[Dos_Signature];

begin
end.
 
Steps To Reproducecompile the example program in the description.
Additional InformationDelphi compiles the sample program without problem.
TagsNo tags attached.
Fixed in Revision40010
FPCOldBugId
FPCTarget
Attached Files

Activities

Jonas Maebe

2018-10-21 20:49

manager   ~0111505

Also added missing support for character and boolean constants.

Issue History

Date Modified Username Field Change
2018-07-30 10:14 440bx New Issue
2018-10-21 20:49 Jonas Maebe Fixed in Revision => 40010
2018-10-21 20:49 Jonas Maebe Note Added: 0111505
2018-10-21 20:49 Jonas Maebe Status new => resolved
2018-10-21 20:49 Jonas Maebe Fixed in Version => 3.3.1
2018-10-21 20:49 Jonas Maebe Resolution open => fixed
2018-10-21 20:49 Jonas Maebe Assigned To => Jonas Maebe