microsoft / AL

Home of the Dynamics 365 Business Central AL Language extension for Visual Studio Code. Used to track issues regarding the latest version of the AL compiler and developer tools available in the Visual Studio Code Marketplace or as part of the AL Developer Preview builds for Dynamics 365 Business Central.
MIT License
728 stars 241 forks source link

Missing parenthesis in Enum methods throws error in platform but not in compilation time #7629

Open sergiogp1 opened 7 months ago

sergiogp1 commented 7 months ago

1. Describe the bug Missing parenthesis in Enum methods throws error in platform but not in compilation time.

2. To Reproduce Steps to reproduce the behavior:

  1. Create an Enum
enum 70021 "ABC Sale Type"
{
    value(0; A) {}
    value(1; B) {}
}
  1. Add this code
    Txt := Enum::"ABC Sale Type".Names.Get(Enum::"ABC Sale Type".Ordinals.IndexOf(1))

3. Expected behavior AL compiler should throw a clear error because error is thrown later in platform.

4. Actual behavior You can compile but an error is thrown when you try to publish: Unexpected value 'NoConversion' of type 'Microsoft.Dynamics.Nav.CodeAnalysis.ConversionKind') Unexpected value 'NoConversion' of type 'Microsoft.Dynamics.Nav.CodeAnalysis.ConversionKind'

5. Solution: Add parenthesis to Names() method and Ordinals() methods

Txt := Enum::"ABC Sale Type".Names().Get(Enum::"ABC Sale Type".Ordinals().IndexOf(1))

6. Versions:

Final Checklist

Please remember to do the following:

BazookaMusic commented 7 months ago

Thank you for the repro, it's super useful. Happy new year!

bjarkihall commented 7 months ago

Duplicate/related to #7477 ?