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

Analyzer throws Rule0242PartialRecordsDetectJitLoads exception #6848

Closed dsaveyn closed 2 years ago

dsaveyn commented 2 years ago

Please include the following with each issue:

1. Describe the bug A SetLoadFields() call followed by a RequestOptionsPage.Update() call causes the analyzer to throw the following exception:

image

2. To Reproduce Steps to reproduce the behavior:

trigger OnPreDataItem()
var
    Customer: record "Customer";
begin
    Customer.SetLoadFields(Name);
    RequestOptionsPage.Update(); // This line causes the analyzer to throw an exception
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 The code analyzer should not thrown an exception

4. Actual behavior The code analyzer throws an exception: JITIssue

5. Versions:

Final Checklist

Please remember to do the following:

dzzzb commented 2 years ago

It keeps coming back! See original https://github.com/microsoft/AL/issues/6558 and my new https://github.com/microsoft/AL/issues/6891

PhDuck commented 2 years ago

No repro.

dzzzb commented 2 years ago

Repro!

The OP's mentioned "attachments" were missing, but I managed to recreate a minimal scenario that shows their problem.

report 50100 Test
{
    dataset
    {
        dataitem(Customer; Customer)
        {
            trigger OnPreDataItem()
            var
                Customer: record "Customer";
            begin
                Customer.SetLoadFields(Name);
                RequestOptionsPage.Update(); // This line causes the analyzer to throw an exception
            end;
        }
    }

    requestpage
    { }
}

uncommented: borked

image

Analyzer 'Microsoft.Dynamics.Nav.CodeCop.Design.Rule0242PartialRecordsDetectJitLoads' threw an exception of type 'System.InvalidCastException' with message 'System.InvalidCastException: Unable to cast object of type 'Microsoft.Dynamics.Nav.CodeAnalysis.BoundObjectAccess' to type 'Microsoft.Dynamics.Nav.CodeAnalysis.IFieldAccess'.
   at Microsoft.Dynamics.Nav.CodeAnalysis.OperationExtensions.GetSymbol(IOperation operation) in D:\a\1\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\Compilation\OperationExtensions.cs:line 41
   at Microsoft.Dynamics.Nav.CodeCop.Design.Rule0242PartialRecordsDetectJitLoads.JitLoadDetectionVisitor.VisitInvocationExpression(IInvocationExpression operation) in D:\a\1\s\source\Prod\Microsoft.Dynamics.Nav.CodeCop\Design\Rule0242PartialRecordsDetectJitLoads.cs:line 255
   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.VisitArray[T](ImmutableArray`1 list) in D:\a\1\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\Compilation\OperationWalker.cs:line 44
   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 128
   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'

commented: works image


Name: AL Language
Id: ms-dynamics-smb.al
Description: AL development tools for Dynamics 365 Business Central
Version: 8.2.552672
Publisher: Microsoft
VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=ms-dynamics-smb.al
PhDuck commented 2 years ago

It isn't reproducing in the dev branch since it was already fixed. It seems it wasn't backported to release branch, will do that now.

dzzzb commented 2 years ago

Thanks!