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

AA0242: Triggering warning twice for same field throws System.ArgumentException: An item with the same key has already been added #6564

Closed dzzzb closed 3 years ago

dzzzb commented 3 years ago

1. Describe the bug If the AA0242 diagnostic is tripped twice for the same field, it can't handled it and blows up.

2. To Reproduce

pageextension 50100 CustomerListExt extends "Customer List"
{
    trigger OnOpenPage();
    var
        Customer: Record Customer;
        Name: Text;
    begin
        Customer.SetLoadFields("No.");
        Customer.FindFirst();
        Name := Customer.Name;
        Name := Customer.Name;
    end;
}

3. Expected behavior Two warnings.

4. Actual behavior image

Analyzer 'Microsoft.Dynamics.Nav.CodeCop.Design.Rule0242PartialRecordsDetectJitLoads' threw an exception of type 'System.ArgumentException' with message 'System.ArgumentException: An item with the same key has already been added. Key: Name
   at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
   at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
   at Microsoft.Dynamics.Nav.CodeCop.Design.Rule0242PartialRecordsDetectJitLoads.JitLoadDetectionVisitor.VisitFieldAccess(IFieldAccess operation) in D:\a\1\s\source\Prod\Microsoft.Dynamics.Nav.CodeCop\Design\Rule0242PartialRecordsDetectJitLoads.cs:line 201
   at Microsoft.Dynamics.Nav.CodeAnalysis.OperationWalker.Visit(IOperation operation) in D:\a\1\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\Compilation\OperationWalker.cs:line 36
   at Microsoft.Dynamics.Nav.CodeAnalysis.OperationWalker.Visit(IOperation operation) in D:\a\1\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\Compilation\OperationWalker.cs:line 36
   at Microsoft.Dynamics.Nav.CodeAnalysis.OperationWalker.VisitAssignmentStatement(IAssignmentStatement operation) in D:\a\1\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\Compilation\OperationWalker.cs:line 67
   at Microsoft.Dynamics.Nav.CodeAnalysis.BoundAssignmentStatement.Accept(OperationVisitor visitor) in D:\a\1\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\BoundTree\Statements.cs:line 113
   at Microsoft.Dynamics.Nav.CodeAnalysis.OperationWalker.Visit(IOperation operation) in D:\a\1\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\Compilation\OperationWalker.cs:line 36
   at Microsoft.Dynamics.Nav.CodeAnalysis.OperationWalker.VisitArray[T](ImmutableArray`1 list) in D:\a\1\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\Compilation\OperationWalker.cs:line 42
   at Microsoft.Dynamics.Nav.CodeAnalysis.OperationWalker.VisitBlockStatement(IBlockStatement operation) in D:\a\1\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\Compilation\OperationWalker.cs:line 49
   at Microsoft.Dynamics.Nav.CodeAnalysis.BoundBlock.Accept(OperationVisitor visitor) in D:\a\1\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\BoundTree\Statements.cs:line 84
   at Microsoft.Dynamics.Nav.CodeAnalysis.OperationWalker.Visit(IOperation operation) in D:\a\1\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\Compilation\OperationWalker.cs:line 36
   at Microsoft.Dynamics.Nav.CodeCop.Design.Rule0242PartialRecordsDetectJitLoads.AnalyzeMethod(OperationAnalysisContext context) in D:\a\1\s\source\Prod\Microsoft.Dynamics.Nav.CodeCop\Design\Rule0242PartialRecordsDetectJitLoads.cs:line 125
   at Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics.AnalyzerExecutor.<>c__DisplayClass53_1.<ExecuteOperationAction>b__1() in D:\a\1\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\DiagnosticAnalyzer\AnalyzerExecutor.cs:line 764
   at Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock(DiagnosticAnalyzer analyzer, Action analyze, Nullable`1 info) in D:\a\1\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\DiagnosticAnalyzer\AnalyzerExecutor.cs:line 1100'

5. Versions:

PhDuck commented 3 years ago

@qutreson please assign to me.

PhDuck commented 3 years ago

@atoader this has been fixed, we can close this issue.

JesperSchulz commented 3 years ago

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

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

For more details on code branches and docker images please read: https://blogs.msdn.microsoft.com/nav/2018/05/03/al-developer-previews-multiple-releases-and-github/ https://freddysblog.com/2020/06/25/working-with-artifacts/