AL
AL copied to clipboard
Semantics are lost on Enum values if AsInteger has no parentheses
Please include the following with each issue:
1. Describe the bug This bug has been discussed to some degree in a yammer thread (https://www.yammer.com/dynamicsnavdev/#/Threads/show?threadId=2331527012761600) but this ticket is created for easier tracking/discovery and discussion.
Basically, Enum.AsInteger lose semantic highlighting and hover won't give you a tooltip if the parenthesis are missing. Method chains still work without any parenthesis needed, if that information helps. I noticed another case where indexing an array with an Enum would cause a warning (previously I think it was an error but it raises an AL0603 warning now). It might be related to AL Namespaces?
I have AL Language version (v12.0.842197), the runtime is 11 though, if that makes a difference. Just let me know if I can help any further, and thanks for looking into this.
2. To Reproduce Here I've tried some of the different scenarios that came to mind:
procedure Repro()
var
MyJsonToken: JsonToken;
MyClientTypeEnum: Enum "Client Type";
MyArr: array[1] of Text;
begin
Message('', Enum::"Client Type"::ODataV4.AsInteger); // no error/warning but loses semantics
Message('', Enum::"Client Type"::ODataV4.AsInteger()); // works
Message('', Enum::"Client Type"::ODataV4.AsInteger(), Enum::"Client Type"::ODataV4.AsInteger());
Message('', MyArr[Enum::"Client Type"::ODataV4.AsInteger]); // raises warning
Message('', MyArr[Enum::"Client Type"::ODataV4.AsInteger()]); // does not
Message('', MyClientTypeEnum::ODataV4.AsInteger); // static vs. variable works the same
Message('', MyClientTypeEnum::ODataV4.AsInteger());
Message('', MyJsonToken.AsValue.AsInteger);
end;
Passing them as parameters also causes the warning, not just using them as array indexes:
Message(Format('', Enum::"Client Type"::ODataV4.AsInteger)); // warning
Message(Format('', Enum::"Client Type"::ODataV4.AsInteger())); // works
Also, since it doesn't know that AsInteger has changed it from EnumValue to Integer, it raises a warning when you try to assign it to an Integer variable:
MyInt := Enum::"Client Type"::ODataV4.AsInteger;
Also note that using these as return values reverses the issue:
procedure Test(): Enum "Client Type"
begin
exit(Enum::"Client Type"::ODataV4.AsInteger); // now this works but should raise a warning
end;
procedure Test2(): Integer
begin
exit(Enum::"Client Type"::ODataV4.AsInteger); // this throws a warning but should work
end;
procedure Test3(): Enum "Client Type"
begin
exit(Enum::"Client Type"::ODataV4.AsInteger()); // this works as expected (raises a warning)
end;
3. Expected behavior I expect AsInteger and AsInteger() to work the same. This is just a simple case but there might be a related use-case / pattern which might also silently break once we upgrade to v12.
4. Actual behavior
Here are the current results:
Note that playing around with these also made the formatter go rogue like adding linebreaks to 3439, but reloading vscode seemed to fix it, this kind of stuff might be expected when the intention is to break the lexer, so it might not be relevant but I decided to include it here if it's relevant:
5. Versions:
- AL Language: v12.0.842197
- Visual Studio Code: 1.81
- Business Central: 22.3
- List of Visual Studio Code extensions that you have installed: AL Language Extension
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