Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2022-09

Enum property can't be published

7 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Hairy Pixels

I just tried to build a lazarus project using 3.3.1/ppca64 and I’m getting an error that an enum can’t be published. This was working on 3.2.2/ppcx64 so what changed?

=======================================

lazbuild ./pasls.lpi --widgetset=cocoa --compiler=/usr/local/lib/fpc/3.3.1/ppca64 --cpu=aarch64 Free Pascal Compiler version 3.3.1 [2022/09/15] for aarch64 Copyright (c) 1993-2022 by Florian Klaempfl and others (1002) Target OS: Darwin for AArch64

=======================================

  TDiagnosticSeverity = ( Error = 1,
                          Warning = 2,
                          Information = 3,
                          Hint = 4
                          );
  TDiagnostic = class (TCollectionItem)
  private
    fSeverity: TDiagnosticSeverity;
  published
    property severity: TDiagnosticSeverity read fSeverity write fSeverity;  //  error: (3134) This kind of property cannot be published

Regards,
Ryan Joseph

Reply by email

Marco van de Voort
to Hairy Pixels
Hairy Pixels wrote 24 lines
I just tried to build a lazarus project using 3.3.1/ppca64 and I’m getting an error that an enum can’t be published. This was working on 3.2.2/ppcx64 so what changed? ======================================= lazbuild ./pasls.lpi --widgetset=cocoa --compiler=/usr/local/lib/fpc/3.3.1/ppca64 --cpu=aarch64 Free Pascal Compiler version 3.3.1 [2022/09/15] for aarch64 Copyright (c) 1993-2022 by Florian Klaempfl and others (1002) Target OS: Darwin for AArch64 ======================================= TDiagnosticSeverity = ( Error = 1, Warning = 2, Information = 3, Hint = 4 ); TDiagnostic = class (TCollectionItem) private fSeverity: TDiagnosticSeverity; published property severity: TDiagnosticSeverity read fSeverity write fSeverity; // error: (3134) This kind of property cannot be published

3.2.2 compiles without warnings,  3.3.1 (i386-win32 from 17 sept:)

ptt.pp(14,44) Warning: This property will not be published

Possibly enums with assigned values (which can have gaps) are not safe to publish, and this was only now noted?

Reply by email

Hairy Pixels
to Marco van de Voort
Show quoted text 7 lines
On Sep 27, 2022, at 4:17 PM, Marco van de Voort via fpc-pascal wrote: 3.2.2 compiles without warnings, 3.3.1 (i386-win32 from 17 sept:) ptt.pp(14,44) Warning: This property will not be published Possibly enums with assigned values (which can have gaps) are not safe to publish, and this was only now noted?

I must have missed that.

What’s a good solution here? It looks like the code needs these enums to be 1 indexed, otherwise they are all in order with no gaps. If I could publish those and just do a +1 first that would work.

Regards,
Ryan Joseph

Reply by email

Pierre Muller
to Hairy Pixels

Le 27/09/2022 à 11:22, Hairy Pixels via fpc-pascal a écrit :

Show quoted text 13 lines
> On Sep 27, 2022, at 4:17 PM, Marco van de Voort via fpc-pascal wrote: > > 3.2.2 compiles without warnings, 3.3.1 (i386-win32 from 17 sept:) > > ptt.pp(14,44) Warning: This property will not be published > > Possibly enums with assigned values (which can have gaps) are not safe to publish, and this was only now noted? I must have missed that. What’s a good solution here? It looks like the code needs these enums to be 1 indexed, otherwise they are all in order with no gaps. If I could publish those and just do a +1 first that would work.

Wouldn't adding NoError in front of the enum work for this case? You don't need the explicit values, and their would not change!

   TDiagnosticSeverity = ( NoError { will be 0},
			  Error {will stay equal to 1},
                           Warning {will stay equal to 2},
                           Information  {will stay equal to 3},
                           Hint {will stay equal to 4}
                           );

Not a general solution, but a very simple one in that specific case!

Pierre

Reply by email

Ondrej Pokorny
to Hairy Pixels: I must have missed that. What’s a good solution here? It looks like the code needs…
Hairy Pixels wrote 10 lines
> On Sep 27, 2022, at 4:17 PM, Marco van de Voort via fpc-pascal wrote: > > 3.2.2 compiles without warnings, 3.3.1 (i386-win32 from 17 sept:) > > ptt.pp(14,44) Warning: This property will not be published > > Possibly enums with assigned values (which can have gaps) are not safe to publish, and this was only now noted? I must have missed that. What’s a good solution here? It looks like the code needs these enums to be 1 indexed, otherwise they are all in order with no gaps. If I could publish those and just do a +1 first that would work.

Publishing enums with gaps didn't work in 3.2.2, even if they compiled. This bug has been fixed.

I can think of these 2 solutions:

1.) Add "unused" enum values to the enum:

TMyEnum = (meOne = 1, meTwo, meThree, meFive = 5);
will become:
TMyEnum = (meUnused1, meOne, meTwo, meThree, meUnused2, meFive);

2.) publish their ordinal value

public
   property MyEnum: TMyEnum read FMyEnum write FMyEnum;
published
   property MyEnumOrd: Integer read GetMyEnumOrd write SetEnumOrd; //
gets/sets MyEnum as ordinal value

Ondrej

Reply by email

Hairy Pixels
to Pierre Muller: Le 27/09/2022 à 11:22, Hairy Pixels via fpc-pascal a écrit : Wouldn't adding NoError…
Show quoted text 11 lines
On Sep 27, 2022, at 5:19 PM, Pierre Muller via fpc-pascal wrote: TDiagnosticSeverity = ( NoError { will be 0}, Error {will stay equal to 1}, Warning {will stay equal to 2}, Information {will stay equal to 3}, Hint {will stay equal to 4} ); Not a general solution, but a very simple one in that specific case!

I like that actually, thanks. There’s a number of these 1 indexed enums but I think this trick will work in most cases.

I know some languages have the convention where you can set just the first index of the first value to set the indexing. That would be a good feature to add to Pascal so we can still publish the enums safely for APIs that have 1 indexing.

TDiagnosticSeverity = ( Error = 1,
Warning,
Information,
Hint

                         );

Regards,
Ryan Joseph

Reply by email