Skip to content

Fix S8969 FP: Implicit conversion is not taken into account #9830

Description

@drieseng

Description

When a given type implements an implicit conversion that can return null, S8969 does not take this into consideration.

Reproducer

internal sealed class Foo
{
    public static implicit operator string?(Foo foo)
    {
        return null;
    }

    public static void Do(Foo foo)
    {
        string x = foo!; // S8969 is reported while the implicit operator can effectively return null
    }
}

Product and Version

SonarAnalyzer.CSharp version 10.33.0.1635

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions