Closed makuhn closed 4 years ago
Does this happen for equals or only less/greater type operators? The latter shouldn't be used anyway as it's a terrible pattern to assume that a lower integral value must always mean a lower conceptual state.
This happens when using less/greater type operator. Using =
or <>
works.
Just IMO, less/greater should become an error with proper enum
s, and not be work-around-able. >:-)
Hi! In this case, the warning is correctly emitted. To perform the comparison, the compiler and the runtime will convert the enum into an integer. Considering that enums are extensible, using numerical comparison might lead to unexpected results.
Comparing an enum field with a specific value using the scope operator is displayed as a warning. Disabling the warning requires using AsInteger for both sides of expression. This doesn't make sense in this context and impairs code readability.
Actual code example from Microsoft Base Application, Codeunit 99000845 "Reservation Management", function IssueActionMessage with warning:
Modified code that suppressed the warning:
Screenshots
Version Name: AL Language Id: ms-dynamics-smb.al Description: AL development tools for Dynamics 365 Business Central Version: 5.0.271898 Publisher: Microsoft