Inline scoped enums

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Inline scoped enums

Free Pascal - General mailing list
How can this code
{$scopedenums on}
type
        Bar = set of (A, B, C);
refer to A, B, C?
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Inline scoped enums

Mattias Gaertner
On Fri, 6 Apr 2018 21:38:59 +0300
Роман via fpc-pascal <[hidden email]> wrote:

> How can this code
> {$scopedenums on}
> type
> Bar = set of (A, B, C);
> refer to A, B, C?

Bar.A

Mattias
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Inline scoped enums

Free Pascal - General mailing list
In reply to this post by Free Pascal - General mailing list
 >> How can this code
 >> {$scopedenums on}
 >> type
 >> Bar = set of (A, B, C);
 >> refer to A, B, C?
 > Bar.A
 >
Actually Bar.A won't work, notice the "set of".
Same problem with var x: (a, b, c).
I wonder could they make such code to not compile at all...
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Inline scoped enums

Alexander Grotewohl
indeed. there are other type declarations where 'set of' is valid, so
maybe it inadvertently piggybacks on those

to correct the code.. something like:

{$scopedenums on}
type
   bar = (a, b, c);
var
   foo: set of bar;
begin
   foo:=[bar.a, bar.c];
   if bar.a in foo then
     writeln('yay obscure pascal features! :)');
end.

On 4/7/2018 9:33 PM, Роман via fpc-pascal wrote:

> >> How can this code
> >> {$scopedenums on}
> >> type
> >>     Bar = set of (A, B, C);
> >> refer to A, B, C?
> > Bar.A
> >
> Actually Bar.A won't work, notice the "set of".
> Same problem with var x: (a, b, c).
> I wonder could they make such code to not compile at all...
> _______________________________________________
> fpc-pascal maillist  -  [hidden email]
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Inline scoped enums

Mattias Gaertner
In reply to this post by Mattias Gaertner
On Sat, 7 Apr 2018 08:52:43 +0200
Mattias Gaertner <[hidden email]> wrote:

> On Fri, 6 Apr 2018 21:38:59 +0300
> Роман via fpc-pascal <[hidden email]> wrote:
>
> > How can this code
> > {$scopedenums on}
> > type
> > Bar = set of (A, B, C);
> > refer to A, B, C?  
>
> Bar.A

I correct myself:
Bar.A is wrong.
A is right.

It's a bug in FPC.

Mattias
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Inline scoped enums

Mattias Gaertner
On Sun, 8 Apr 2018 09:22:51 +0200
Mattias Gaertner <[hidden email]> wrote:

> On Sat, 7 Apr 2018 08:52:43 +0200
> Mattias Gaertner <[hidden email]> wrote:
>
> > On Fri, 6 Apr 2018 21:38:59 +0300
> > Роман via fpc-pascal <[hidden email]> wrote:
> >  
> > > How can this code
> > > {$scopedenums on}
> > > type
> > > Bar = set of (A, B, C);
> > > refer to A, B, C?    
> >
> > Bar.A  
>
> I correct myself:
> Bar.A is wrong.
> A is right.
>
> It's a bug in FPC.

It's also buggy in Delphi. As a nested type in a class you cannot
access A, neither with scopedenums of or on:

type
  TC = class
  public
    type TBar = set of (A, B, C);
  end;

Neither A, nor TBar.A, nor TC.TBar.A works in Delphi 10.2.

Mattias


Mattias
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal