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

Rule137DoNotDeclareVariablesThatAreUnused Argument null Exception #4824

Closed f4n0 closed 5 years ago

f4n0 commented 5 years ago

Describe the bug My Settings:

"al.enableCodeAnalysis": true,
    "al.codeAnalyzers": [
        "${CodeCop}"
    ],
Analyzer 'Microsoft.Dynamics.Nav.CodeCop.Design.Rule137DoNotDeclareVariablesThatAreUnused' threw an exception of type 'System.ArgumentNullException' with message 'System.ArgumentNullException: Il valore non può essere null.
Nome parametro: syntax
   in Microsoft.Dynamics.Nav.CodeAnalysis.SemanticModel.CheckSyntaxNode(SyntaxNode syntax) in F:\a\185\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\Compilation\SemanticModel.cs:riga 1462
   in Microsoft.Dynamics.Nav.CodeAnalysis.SemanticModel.GetSymbolInfo(ExpressionSyntax expression, CancellationToken cancellationToken) in F:\a\185\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\Compilation\SemanticModel.cs:riga 547
   in Microsoft.Dynamics.Nav.CodeCop.Design.Rule137DoNotDeclareVariablesThatAreUnused.UnusedVariableAnalyzer.AnalyzeSyntaxNode(SyntaxNodeAnalysisContext context) in F:\a\185\s\source\Prod\Microsoft.Dynamics.Nav.CodeCop\Design\Rule137DoNotDeclareVariablesThatAreUnused.cs:riga 172
   in Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics.AnalyzerExecutor.<>c__DisplayClass52_1.<ExecuteSyntaxNodeAction>b__1() in F:\a\185\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\DiagnosticAnalyzer\AnalyzerExecutor.cs:riga 745
   in Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock(DiagnosticAnalyzer analyzer, Action analyze, Nullable`1 info) in F:\a\185\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\DiagnosticAnalyzer\AnalyzerExecutor.cs:riga 1082'

Versions:

JohanStenberg100 commented 5 years ago

Hi @stefanoPrimo, thanks for filing this issue. Can you please try and figure out what part of your code generates this exception? Without a code snippet to analyze, we can't figure out how to trigger the exception you are experiencing.

f4n0 commented 5 years ago

Hi @JohanStenberg100, thanks for the quick response. Honestly, I don't really know where is the code that throws that error because in the extension there are like 121 Files (with al extension) and this error is pointing to the app.json file (that I don't think that is here the problem). Is there some file that I could debug to find out where is the problem?

f4n0 commented 5 years ago

I've found where is the problem: all it is due to the variable dataType "Dialog". Given that I removed all Dialog variables to a codeunit and the code cop turned back alive!

JohanStenberg100 commented 5 years ago

@stefanoPrimo thanks for figuring it out. Can you provide me with a small sample AL file which reproduces this error? Simply using a Dialog variable doesn't cut it. Thanks

f4n0 commented 5 years ago

Hi, I've recreated the error, here you are: ALProject6.zip

JohanStenberg100 commented 5 years ago

Hi again @stefanoPrimo, I can now reproduce this locally, thanks!

ALGitHubBot commented 5 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 31126 and VS Code Extension Version 3.0.117557.

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://blogs.msdn.microsoft.com/freddyk/2018/04/16/which-docker-image-is-the-right-for-you/

fvet commented 5 years ago

@JohanStenberg100

Working with AL build 3.0.126610 still shows me the 'Rule137DoNotDeclareVariablesThatAreUnused' multiple times. Project is however too large to pinpoint the source ...

Analyzer 'Microsoft.Dynamics.Nav.CodeCop.Design.Rule137DoNotDeclareVariablesThatAreUnused' threw an exception of type 'System.ArgumentNullException' with message 'System.ArgumentNullException: Value cannot be null.
Parameter name: syntax
   at Microsoft.Dynamics.Nav.CodeAnalysis.SemanticModel.CheckSyntaxNode(SyntaxNode syntax) in F:\a\435\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\Compilation\SemanticModel.cs:line 1462
   at Microsoft.Dynamics.Nav.CodeAnalysis.SemanticModel.GetSymbolInfo(ExpressionSyntax expression, CancellationToken cancellationToken) in F:\a\435\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\Compilation\SemanticModel.cs:line 547
   at Microsoft.Dynamics.Nav.CodeCop.Design.Rule137DoNotDeclareVariablesThatAreUnused.UnusedVariableAnalyzer.AnalyzeSyntaxNode(SyntaxNodeAnalysisContext context) in F:\a\435\s\source\Prod\Microsoft.Dynamics.Nav.CodeCop\Design\Rule137DoNotDeclareVariablesThatAreUnused.cs:line 172
   at Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics.AnalyzerExecutor.<>c__DisplayClass52_1.<ExecuteSyntaxNodeAction>b__1() in F:\a\435\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\DiagnosticAnalyzer\AnalyzerExecutor.cs:line 745
   at Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock(DiagnosticAnalyzer analyzer, Action analyze, Nullable`1 info) in F:\a\435\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\DiagnosticAnalyzer\AnalyzerExecutor.cs:line 1082'
JohanStenberg100 commented 5 years ago

Hi @fvet, I have backported this to the 3.0.X release yesterday. It will be available in the next update. Remember, fixes here target the latest preview, but this issue in particular has been backported.