[fpc-devel] [Suggestion] Enumeration range-check intrinsic
J. Gareth Moreton
gareth at moreton-family.com
Tue Jul 2 23:20:11 CEST 2019
That is exactly how it should behave, because the left-side value may
not be valid, and the is operator is meant to help confirm that.
In the meantime, I've updated your patch to work with the current trunk:
https://bugs.freepascal.org/view.php?id=33603#c117040
Gareth aka. Kit
On 02/07/2019 21:31, Ondrej Pokorny wrote:
> On 02.07.2019 21:48, J. Gareth Moreton wrote:
>> I should probably test this myself, but if you, say, read a value
>> from a file directly into a variable of type TEnumType, will your
>> patch return False for "if (Value is TEnumType) then" if Value,
>> despite being TEnumType, contains an invalid value? No problem if it
>> isn't, just that you would have to read an Integer-type first then
>> typecast it.
>
> Yes:
>
> var
> Value: TEnumType;
> begin
> Value := TEnumType(-1);
> IsValid := Value is TEnumType; // IsValid gains false
>
> The compiler may not do any optimizations here (like return always
> true if the left side value is the enum type at the right side). This
> should be clearly stated and documented if the feature is added to FPC.
>
> This is similar to the object-is operator that gets evaluated as well
> even if the type of the left-side value is the type at right side:
>
> var
> Value: TPersistent;
> begin
> Value := TPersistent(TObject.Create);
> IsValid := Value is TPersistent; // IsValid gains false
>
> Ondrej
>
> _______________________________________________
> fpc-devel maillist - fpc-devel at lists.freepascal.org
> https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
>
>
---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
More information about the fpc-devel
mailing list