[fpc-devel] Dangerous optimization in CASE..OF

Ondrej Pokorny lazarus at kluug.net
Sun Apr 15 11:09:12 CEST 2018


On 15.04.2018 0:05, Martok wrote:
> All this is not quite as easy to get right as it seems on the surface. 
> But I do like the the "v is TEnum" operator from the other side of 
> this thread, regardless of where this goes... 

I don't want to force FPC to any direction. I just want to have a simple 
built-in method to validate an ordinal value against an enum. Be it the 
AS/IS operator or a new compiler intrinsic. I chose the AS/IS operators 
because they are easier to implement for me.

It should not change any kind of religion or anything else, they are 
just helpful tools.

Please note that I want to support all ordinal values on the left side 
of the operator. You can then validate a value of variable of the enum 
type itself. Then you can use code like:

var
   E: TMyEnum;

// ...

if not (E is TMyEnum) then
   // handle your error here
else
case E of
   one:
   two:
else
   // handle possible valid values not listed above
end;

That should be OK for all of us.

Ondrej




More information about the fpc-devel mailing list