AL icon indicating copy to clipboard operation
AL copied to clipboard

False positive for AA0206 when using DateTime.Date() or DateTime.Time()

Open wbor-nvt opened this issue 1 year ago • 5 comments

Please include the following with each issue:

1. Describe the bug

When using the new .Date() and .Time() functions of a DateTime variable, the AL compiler throws a warning that the DateTime variable is not used.

The variable 'NewDateTime' is initialized but not used. AL(AA0206)

2. To Reproduce Steps to reproduce the behavior:

local procedure TestNewDateTime_WithWarning()
    var
        NewDateTime: DateTime;
        NewDate: Date;
        NewTime: Time;
    begin
        NewDateTime := CurrentDateTime();
        NewDate := NewDateTime.Date();
        NewTime := NewDateTime.Time();
    end;

    local procedure TestNewDateTime_WithoutWarning()
    var
        NewDateTime: DateTime;
        NewDate: Date;
        NewTime: Time;
    begin
        NewDateTime := CurrentDateTime();
        NewDate := DT2Date(NewDateTime);
        NewTime := DT2Time(NewDateTime);
    end;

Note: Because the developers need to copy and paste the code snippet, including a code snippet as a media file (i.e. .gif) is not sufficient.

3. Expected behavior Should not throw a warning as the DateTime variable has been used.

4. Actual behavior

Image

The variable 'NewDateTime' is initialized but not used. AL(AA0206)

5. Versions:

  • AL Language: v15.0.1177813
  • Visual Studio Code: 1.94.2
  • Business Central: 25.0
  • List of Visual Studio Code extensions that you have installed:
  • Operating System:
    • [x] Windows
    • [ ] Linux
    • [ ] MacOS

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

Internal work item: AB#572542

wbor-nvt avatar Oct 16 '24 13:10 wbor-nvt

Also facing the same issue...

fvet avatar Feb 06 '25 16:02 fvet

Also experiencing the same issue:

Image

someC0d3r avatar Feb 10 '25 14:02 someC0d3r

@krupybalu @BazookaMusic Can you please have a look? This shouldn't be hard to fix and it currently prevents partners to use these new functions.

TKapitan avatar Feb 19 '25 00:02 TKapitan

We receive the same warning. The bug is still present in BC26. When will the bug be fixed?

GOB-Andrea avatar Mar 26 '25 11:03 GOB-Andrea

@BazookaMusic Was this overlooked?

NKarolak avatar Mar 26 '25 11:03 NKarolak

The fix for this issue has been checked in to the master branch. It is available in the bcinsider.azurecr.io/bcsandbox-master Docker image starting from platform build number 27.0.33621.0 and VS Code Extension Version 16.0.1474884.

If you don’t have access to these images you need to become part of the Ready2Go program: aka.ms/readytogo

krupybalu avatar Jul 15 '25 08:07 krupybalu