[fpc-devel] [Suggestion] Enumeration range-check intrinsic

Michael Van Canneyt michael at freepascal.org
Sat Jul 13 21:26:08 CEST 2019



On Sat, 13 Jul 2019, Ondrej Pokorny wrote:

>
>> Even to such a degree that the compiler would
>> simply reject your code by not allowing is/at on a variable of the type
>> itself. Also defendable.
>
> No - not this one. Don't forget about e.g. generics:
> function Test<T>(MyValue: T): Boolean;
> begin
>   Result := MyValue is TMyEnum;
> end;
> would compile for all enumeration types but not for MyValue:TMyEnum. 
> That doesn't make sense.
>
> Better to have a compiler hint/warning when such a construct is found 
> and optimized. This perfectly corresponds with the fact that also 
> constructs like "SmallIntValue is Integer" can be optimized away but 
> must be allowed.

Fair enough. 
Like I said: The point is defendable. So is your point of view.

Personally I am OK with either point of view. 
I am just interested in the ordinal, to make an easier check possible.

I think all sides have now been reviewed to the point of boring or
annoying each other almost to death, and we finally need to decide on 
whether the patch is applied, and if so, which parts of it.

Michael.


More information about the fpc-devel mailing list