csharpsquid:S3400 should not apply to default interface implementations

Sonar version: Version 9.3 (build 51899)

Rule csharpsquid:S3400 (methods should not return constants) should not be applied to default interface implementations introduced in .NET Core 3.0.
Even if the default implementation returns a constant, other implementations might not. This is similar to how virtual methods work.

interface ISomeInterface {
    public bool IsCondition() => true; // this triggers the rule

class SomeClass implements ISomeInterface {
    public bool Value { get; set; }
    public bool IsCondition() => Value; // this is not a constant

Hi @m-gallesio,

thanks for reporting the issue. I can confirm this is a false positive.

I’ve added an issue on our GitHub repository and you can follow the progress here: Rule S3400: FP when using default interface implementation · Issue #5498 · SonarSource/sonar-dotnet · GitHub

1 Like