AL icon indicating copy to clipboard operation
AL copied to clipboard

TestField does not support Enums / raises a warning

Open salgiza opened this issue 6 years ago • 14 comments

There is not much more to add: TestField seems to cast the enum to an Integer, even though the field is defined as an Enum, and that raises a casting warning:

An implicit conversion is being performed from a value of type 'Enum "Gen. Journal Document Type"' to a value of type 'Integer'. This conversion can lead to unexpected runtime issues. This warning will become an error in a future release.AL(AL0603)

image

This was mentioned as a comment in ticket #5693 , but its main subject was unrelated, so I thought that it would be useful to raise this bug on its own.

This was tested with version 5.0.236243 of the AL extension.

salgiza avatar Mar 05 '20 13:03 salgiza

I think you can rewrite as: image

The issue I get now: I can assign a integer value for an Enum field. image

hgnamvn avatar Mar 06 '20 01:03 hgnamvn

@hgnamvn The irony is that, if we do that, the AL code analyzer should raise a warning, because we are actually doing an implicit casting of an enum to an Integer (in the first param of TestField, when the method gets the value).

That being said, nice to know, at least that can help us ignore some of the warnings until they fix it!

salgiza avatar Mar 06 '20 08:03 salgiza

Hi @salgiza ! We're going to look into it in the next week. Thanks for reporting!

atoader avatar Mar 07 '20 08:03 atoader

To temporarily ignore this warning, I would recommend adding a rule to codecop rulest.json file. Something like this:

{
    "id": "AL0603",
    "action": "Hidden",
    "justification": "Implicit conversion from Enum to Integer. ... Hide warning until ..."
}

This avoids the issue of temporarily adding code you don't want to your repository, ...

gregoral avatar Mar 27 '20 12:03 gregoral

26 days ago and this is still a problem?

aobsgit avatar Apr 02 '20 06:04 aobsgit

Today I have created container for versio 16.0.11240.12076-cz and tried to use the TestLibraries and import of _Microsoft_Tests-TestLibraries.app leads to plenty of these warnings. I cannot remove them because the ruleset is not used when importing the app (or can I somehow use some rules for this?). All this makes the CI pipelines failing on the warnings just hen preparing container!

This is now for us high priority.

kine avatar Apr 02 '20 09:04 kine

@kine currently working on this. Why is your CI pipeline failing on this warning?

atoader avatar Apr 02 '20 09:04 atoader

@atoader some pipelines are configured with zero-warning tolerance on e.g. master. NavContainerHelper's Compile-AppInNavContainer parameter Failon can be set up like this but I'd also figure this would be common in custom build pipelines too, since I'd think most people would like their master to be clean, both of errors and warnings. Otherwise warnings can slip in unnoticed and pile up over time. I'm not sure if this is kine's case however, just guessing! :)

bjarkihall avatar Apr 07 '20 11:04 bjarkihall

I just wanted to point out for people that are having issues with this rule (AL0603) that the following is possible:

image

You can see how A breaks now, A_BadFix shows enum value -> integer conversion (AsInteger), A_Fix shows integer -> enum value conversion (FromInteger). I had never noticed this method before since it's a static method for the enum object itself, not an enum value.

bjarkihall avatar Apr 07 '20 15:04 bjarkihall

Scratch that last question, I just saw a "bug" label. Sorry for bothering you...

MatjazSega avatar Apr 09 '20 14:04 MatjazSega

Just got here to report the same issue.

jeffreybulanadi avatar Apr 16 '20 00:04 jeffreybulanadi

Just got here just to report the same issue.

jeffreybulanadi avatar Apr 16 '20 01:04 jeffreybulanadi

@atoader We have set the pipeline to fail on warnings, as @bjarkihall guessed to keep the code clean. Now we needed to switch to "unsafe" way when warnings are accepted or we need to hide them through ruleset. But there is danger that the rule will be there forever, because nobody will clean it up in all our apps later...

kine avatar Apr 16 '20 07:04 kine

Closing as this has been fixed since at least the 17.0 release.

thloke avatar Jul 21 '21 06:07 thloke