Navigation Menu

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

Fix S1168: FP with local function #2119

Closed
andrei-epure-sonarsource opened this issue Nov 22, 2018 · 0 comments
Closed

Fix S1168: FP with local function #2119

andrei-epure-sonarsource opened this issue Nov 22, 2018 · 0 comments
Assignees

Comments

@andrei-epure-sonarsource
Copy link
Contributor

andrei-epure-sonarsource commented Nov 22, 2018

Description

csharpsquid:S1168 (Empty arrays and collections should be returned instead of null) raises an issue when the returned type is not a collection/array, but the roslyn IArrayTypeSymbol.

Repro steps

  1. Create a method that returns IEnumerable and returns a not-null result
  2. Inside this method, create a local function that returns a non-enumerable type
  3. Return null inside the local function
private IEnumerable<Instruction> Foo()
{
  var instructions = new List<Instruction>();
  // some logic
  return instructions;

  IArrayTypeSymbol LocalBar(SyntaxNode parent)
  {
    return null; // FP
  }
}

Expected behavior

Should not raise issue.

Actual behavior

csharpsquid:S1168 "Return an empty collection instead of null."

Related information

  • SonarC# Version "7.9 (build 7566)"
@Evangelink Evangelink changed the title Fix S1168: should not raise when return type of local function is not enumerable Fix S1168: FP with local function Dec 14, 2018
@ghost ghost assigned Evangelink Dec 14, 2018
@ghost ghost added the Status: Needs Review label Dec 14, 2018
@ghost ghost removed the Status: Needs Review label Dec 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants