Skip to content

Commit

Permalink
Fix S3237: NullReferenceException with arrow expression of interface …
Browse files Browse the repository at this point in the history
…member (#2252)
  • Loading branch information
Godin authored and Amaury Levé committed Jan 29, 2019
1 parent e70d4f7 commit 4b42716
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ protected override void Initialize(SonarAnalysisContext context)
var interfaceMember = c.SemanticModel.GetDeclaredSymbol(accessor).GetInterfaceMember();
if (interfaceMember != null &&
accessor?.Body.Statements.Count == 0) // No need to check ExpressionBody, it can't be empty
accessor.Body?.Statements.Count == 0) // No need to check ExpressionBody, it can't be empty
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,24 @@ public override event EventHandler Bar3
}
}

// implement interface using arrow syntax
public class Baz : IFoo
{
private int foo1;

public int Foo1
{
get => 42;
set => foo1 = 0; // Noncompliant
}

public event EventHandler Bar3
{
add => throw new Exception();
remove => throw new Exception();
}
}

public class NewSyntax
{
public int ReadonlyGetter { get; }
Expand Down

0 comments on commit 4b42716

Please sign in to comment.