Describe the bug
A publish started failing with the following message:
Unexpected value 'Joker' of type 'Microsoft.Dynamics.Nav.CodeAnalysis.NavTypeKind'
after series of commits in tons of files from various people from various branches.
To find the bug I had to find a point in the git history where publishing worked and step through each commit, reload vscode each time (because else the vscode extension didn't reproduce the error), do a full publish which takes 5 minutes each time since this was in a huge extension, until I finally found the commit causing the issue. After adding the changes file-by-file I finally found the the line causing it.
A change which looked similar to the repro I provide here had been made in a bulk attempt to follow the newly added AL0603 rule (no implicit casting of Option | Integer <-> Enum):
"An implicit conversion is being performed ...".
So here's what's wrong:
To Reproduce
enum 55540 FooEnum
{
Extensible = true;
value(0; a) { }
value(1; b) { }
value(2; c) { }
}
codeunit 55540 FooCodeUnit
{
procedure Test()
var
e: Enum FooEnum;
begin
Message(Format(Enum::FooEnum.FromInteger(-5))); // works
// compiler throws error in editor:
// Operator '=' cannot be applied to operands of type 'Joker' and 'Enum FooEnum'AL(AL0175)
if Enum::FooEnum.FromInteger(0) = Enum::FooEnum::a then
Message('doesn''t work');
// NO WARNING, ERROR WHEN PUBLISHING:
// Unexpected value 'Joker' of type 'Microsoft.Dynamics.Nav.CodeAnalysis.NavTypeKind'
// With no information on where the error was thrown.
case Enum::FooEnum.FromInteger(0) of
Enum::FooEnum::a:
Message('doesn''t work');
end;
// casting to enum value resolved the issue:
e := Enum::FooEnum.FromInteger(0);
if e = Enum::FooEnum::a then
Message('works');
case e of
Enum::FooEnum::a:
Message('works');
end;
end;
}
Expected behavior
First of all, please try to give a better error message in cases like these - it's really hard to track down bugs that only break on publish.
Second, make sure that "if" and "case of" work the same.
You seem to enforce case over if, so I was surprised to find they didn't throw a similar error:
AA0022 | Substitute the IF THEN ELSE structure with a CASE.
Third, why does FromInteger return Joker type instead of the Enum it belongs to and why isn't FromInteger available in Enum values too? Right now it's only accessible by statically referencing the globally available Enum.
P.S. if the descriptions have a grumpy tone to them it's really not on purpose, I've just spent a lot of time on this and want to prevent others from having to do so too.
Screenshots

5. Versions:
This is clearly a bug. I sorry that you have to spend so much time trying to reproduce, but thank you for taking your time doing that. It will help us fix it quickly.
@esbenk thanks, I'm glad I could help.
Thanks man, I did have the same problem. Too bad TransferDirection.FromInteger("Sourcesubtype") does not exist yet but
Enum::"Transfer Direction".FromInteger("Source Subtype") does.
Don't know if this is anything good for, but the following also fails (not till compilation):
enum 55540 FooEnum
{
Extensible = true;
value(0; a) { }
value(1; b) { }
value(2; c) { }
}
codeunit 55540 FooCodeUnit
{
procedure Test(BarEnum: Enum FooEnum)
{
case BarEnum of
Enum::FooEnum::a:
;
}
}
error AL0104: Syntax error, ':' expected
Version: Platform 14.0.40464.0 + Application 40471 (DE Business Central 14.10)
AL Lang: v4.0.249486
This issue has been fixed in our latest developer preview, the compiler diagnostic about the conversion from enum to joker is not reported anymore.

Most helpful comment
Thanks man, I did have the same problem. Too bad TransferDirection.FromInteger("Sourcesubtype") does not exist yet but
Enum::"Transfer Direction".FromInteger("Source Subtype") does.