Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support switch/case AndPattern #4880

Closed
PieterIddink opened this issue Sep 7, 2021 · 2 comments
Closed

Support switch/case AndPattern #4880

PieterIddink opened this issue Sep 7, 2021 · 2 comments
Labels
Area: CFG/SE CFG and SE related issues. Type: CFG/SE FPs Rule IS triggered when it shouldn't be for CFG and SE rules.
Projects

Comments

@PieterIddink
Copy link

Description

Please add support for switch/case AndPattern.

Repro steps

The following simple C# 8 code example will generate a System.NotSupportedException because the use of the AndPattern when performing a sonar analysis:

public char SomeMethod(int foo)
{
    switch (foo)
    {
        case 0:
            return '0';
        case >= 1 and < 20:
            return '1';
        default:
            throw new ArgumentOutOfRangeException(nameof(foo));
    }
}

Known workarounds

Refactor code to not use 'AndPattern'.

Related information

C# 8
Sonar scanner version: 1.20.0. (https://sonarcloud.io/documentation/analysis/scan/sonarscanner-for-azure-devops/)

Analyzer ouput:

[warning]CSC(0,0): Warning AD0001: Analyzer 'SonarAnalyzer.Rules.SymbolicExecution.SymbolicExecutionRunner' threw an exception of type 'SonarAnalyzer.SymbolicExecution.SymbolicExecutionException' with message 'Error processing method: xxx 
Method file: xxx.cs ## Method line: x,y 
Inner exception: System.NotSupportedException: AndPattern 
   at SonarAnalyzer.SymbolicExecution.CSharpExplodedGraph.VisitInstruction(ExplodedGraphNode node) 
   at SonarAnalyzer.SymbolicExecution.AbstractExplodedGraph.Walk() 
   at SonarAnalyzer.Rules.SymbolicExecution.SymbolicExecutionRunner.Analyze(CSharpExplodedGraph explodedGraph, SyntaxNodeAnalysisContext context) 
   at SonarAnalyzer.Extensions.SonarAnalysisContextExtensions.Analyze(CSharpSyntaxNode declarationBody, ISymbol symbol, Action`2 runAnalysis, SyntaxNodeAnalysisContext context)
@costin-zaharia-sonarsource costin-zaharia-sonarsource added Area: C# C# rules related issues. Type: Improvement Making existing code better. labels Sep 13, 2021
@github-actions github-actions bot added this to Improvement in Backlog Sep 13, 2021
@csaba-sagi-sonarsource csaba-sagi-sonarsource added Area: C#9 and removed Area: C# C# rules related issues. labels Sep 20, 2021
@csaba-sagi-sonarsource
Copy link
Contributor

The SymbolicExecutionRunner does not throw the exception anymore. Proper support has yet to be added.

@pavel-mikula-sonarsource pavel-mikula-sonarsource added the Area: CFG/SE CFG and SE related issues. label Sep 22, 2021
@costin-zaharia-sonarsource costin-zaharia-sonarsource added Type: CFG/SE FPs Rule IS triggered when it shouldn't be for CFG and SE rules. and removed Type: Improvement Making existing code better. labels Oct 25, 2021
@github-actions github-actions bot moved this from Improvement to CFG/SE FPs in Backlog Oct 25, 2021
@pavel-mikula-sonarsource
Copy link
Contributor

We've reimplemented the Symbolic Execution engine, so this should not appear anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: CFG/SE CFG and SE related issues. Type: CFG/SE FPs Rule IS triggered when it shouldn't be for CFG and SE rules.
Projects
No open projects
Backlog
  
CFG/SE FPs
Development

No branches or pull requests

4 participants