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

J. Gareth Moreton gareth at moreton-family.com
Thu Jul 11 13:45:50 CEST 2019


On 11/07/2019 11:52, Ondrej Pokorny wrote:
> BTW, your note in the issue report is very misleading: 
> https://bugs.freepascal.org/view.php?id=33603#c117162.
>
> > The idea behind "is" and "as" is that they are the sole exception to 
> the rule and will return False and raise an error respectively if the 
> enum is out of bounds.
>
> IS/AS are not an exception of the rule - after a long discussion we 
> settled down that if IS/AS is applied on a value of the same 
> enumeration type:
>
> var
>   MyEnumValue: TEnumValue;
> begin
>   if MyEnumValue is TEnumValue then
> // ...
> end;
>
> the compiler will expect that the result is always true. (It doesn't 
> have to check for invalid values.)

Who is "we" in this case? I was under the impression that is/as could be 
used to check if the enumeration was valid or not, as a means to check 
if the enueration contained a valid value or not so as to avoid problems 
with case blocks raising access violations. I guess we've hit 
disagreements again.

Gareth


---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus



More information about the fpc-devel mailing list