microsoft / AL

Home of the Dynamics 365 Business Central AL Language extension for Visual Studio Code. Used to track issues regarding the latest version of the AL compiler and developer tools available in the Visual Studio Code Marketplace or as part of the AL Developer Preview builds for Dynamics 365 Business Central.
MIT License
744 stars 245 forks source link

The variable 'XYZ' is initialized but not used.AL(AA0206) #6207

Closed larswestman closed 2 years ago

larswestman commented 4 years ago

Describe the bug A variable that is assigned a value and used as a source expression for a control will raise this warning

To Reproduce Steps and to reproduce the behavior: Use a variable as source expression. Example below (simplified version of the real page which obviously does not make much sense)

page 12064546 "LTC Consignment Cues"
{
    PageType = CardPart;
    SourceTable = "LTC Consignment Header";
    Caption = 'Totals';
    layout
    {
        area(Content)
        {
            cuegroup(Numbers)
            {
                Caption = ' ';
                ShowCaption = false;                
                field(FieldNoOfItemLines; "NoOfItemLines")
                {
                    ApplicationArea = All;
                    BlankZero = true;
                    Caption = 'Item Lines';                    
                }
            }
        }
    }
    trigger OnOpenPage()
    begin
        NoOfItemLines := 1;
    end;
    var
        NoOfItemLines: Integer;
}

The line "NoOfItemLines := 1;" will have a warning

Expected behavior Should not be a warning

5. Versions:

dzzzb commented 3 years ago

Does the warning go away if you remove the quotes around the variable name? I have just discovered an equivalent warning for variables used as properties in fields and actions.

larswestman commented 3 years ago

Yes, without quoutes the warning goes away.

mazhelez commented 2 years ago

Thanks for reporting this issue. Sorry we haven’t completed it yet, but we’ve had to prioritize elsewhere. We’re planning to give the CodeCop engine and its rules an overhaul in a future major release. Thanks for your patience.

For this case consider using Pragma Warning Directive.