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 S3237: NullReferenceException with arrow expression of interface member #2252

Merged
merged 2 commits into from
Jan 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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