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

Codeunit variable used in repeat..until block in if..then block with begin end loose methods in intellisense #5862

Closed kine closed 2 years ago

kine commented 4 years ago

Describe the bug We have hit a problem, when local codeunit variable (cmdBuilder in the video) loose available methods in the intellisense when used in Repeat..until block with if..then block with beign..end statement. If no begin..end statement is used, all is ok. If repeat..until is not used, all is ok. When it is wrong, there is only Run method listed as available. When it is entered and then removed again, the intellisense shows correctly all references again. Very weird, thus I made the video, see screenshot sections.

Another part (reason or effect, do not know) is, that when the AL is "broken" (not showing the methods), The codeunit variable is marked with error:

'<nameofthecodeunit>' is an ambiguous reference between '<nameofthecodeunit>' defined by the extension 'A by Publisher (1.0.0.0)' and '<nameofthecodeunit>' defined by the extension 'B by Publisher. (1.0.0.0)'.AL(AL0275)

even when the codeunit is defined only in the app B. Seems that it is somehow connected to the fact, that the used codeunit variable is using codeunit defined in dependency app.

Another error which appear when the codeunit is in state that it cannot be compiled (the line is not finished) is this:

Analyzer 'Microsoft.Dynamics.Nav.CodeCop.Design.Rule205VariablesMustAlwaysBeInitialized' threw an exception of type 'System.NullReferenceException' with message 'System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.Dynamics.Nav.CodeCop.Design.Rule205VariablesMustAlwaysBeInitialized.UnusedLocalVariableAnalyzer.AnalyzeSyntaxNode(SyntaxNodeAnalysisContext context) in D:\a\1\s\source\Prod\Microsoft.Dynamics.Nav.CodeCop\Design\Rule205VariablesMustAlwaysBeInitialized.cs:line 484
   at Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics.AnalyzerExecutor.<>c__DisplayClass52_1.<ExecuteSyntaxNodeAction>b__1() in D:\a\1\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\DiagnosticAnalyzer\AnalyzerExecutor.cs:line 742
   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 1099'

And I am not sure if this is not the source of the problem (exception leads to failure of creating the intellisense data)

To Reproduce I am unable to reproduce this in clean app, thus there could be some dependency on the specific code. I am able to send the code if needed to MS.

  1. Have a function with local variable for some codeunit from dependency application
  2. Write this code
        repeat
            if true then begin
                myCodeunit.
            end;
        until true;
  3. The intellisense will show only Run method available after you type the . after myCodeunit
  4. If you remove begin/end and just wryte the myCodeunit. without them, all is ok
  5. If the if then is not there or the repeat until is not there, all is ok

Expected behavior The intellisense is delivering all available methods for the codeunit regardless in which statement the variable is used.

Screenshots Intellisense bug

5. Versions:

github-actions[bot] commented 2 years ago

Hi,

Many thanks for raising this issue. Unfortunately we have not been able to get to this issue as soon as we'd have liked. Since it has been a long time since this issue was last updated, it is possible that this has been fixed by a newer release of Business Central and the AL extension for Visual Studio Code. We have thus decided to close it.

If the issue still affects you on the latest insider build of Business Central, please help us and open a new issue for us with the latest steps to reproduce the issue, and link back to this closed issue to track any comments or discussions.

Thanks,
Thaddeus