AL icon indicating copy to clipboard operation
AL copied to clipboard

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

Open sergiogp1 opened this issue 7 months ago • 2 comments

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:

  • AL Language: I guess 12.1
  • Visual Studio Code: 1.85.1
  • Business Central: 23.1

Final Checklist

Please remember to do the following:

  • [X] Search the issue repository to ensure you are reporting a new issue
  • [X] Reproduce the issue after disabling all extensions except the AL Language extension
  • [X] Simplify your code around the issue to better isolate the problem

sergiogp1 avatar Dec 30 '23 22:12 sergiogp1

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

BazookaMusic avatar Jan 01 '24 20:01 BazookaMusic

Duplicate/related to #7477 ?

bjarkihall avatar Jan 10 '24 10:01 bjarkihall