[fpc-pascal] Scoped enums and inferred types

Michael Van Canneyt michael at freepascal.org
Wed Feb 21 07:54:55 CET 2018

On Wed, 21 Feb 2018, Ryan Joseph wrote:

> I just learned FPC has scoped enums, which is nice, but they lack what you could call “relative inference” based on the type being passed. In the example below the parameter “t” is TMyType but passing “A” doesn’t work. Doesn’t the compiler know the type and can infer “A” is relative to the scoped enum? I understand there’s a possibility for name conflicts but you could just use the full name in that case.
> Is this a missing feature or do you need to enable it or something?
> {$scopedenums on}
> type
> 	TMyType = (A, B, C);
> {$scopedenums off}
> procedure DoThis (t: TMyType);
> begin
> end;
> DoThis(A);

The whole point of scoped enums is to force you to write TMyType.A
So this is "as designed". If you want to be able to write A, don't use
scoped enums.


More information about the fpc-pascal mailing list