C# S1172 and S1854 - False positives with local functions and nullability operator"!"

Trying to narrow down a FP found in a relatively complex method, I managed to reproduce two FPs with the following code:

private static void Test(Action<string> action)
{
    string? str = "xyz";
    LocalFunction();

    void LocalFunction()
    {
        action(str!);
    }
}

The first FP is S1172 on the action parameter and it seems that it happens only if “!” is appended to the argument passed to the function (in order to suggest the nullable variable is not null here), very strange… Also, it does not appear if action is invoked from the main function and not the local function. The behaviour is the same if nullable is enabled or disabled in the project.

The other FP is S1854 as it seems that the analyzer doesn’t recognize that action is later used in LocalFunction. This one doesn’t depend on the “!”

The analyzer version is 8.4.0.15306

Hello Miroslav,

S1172: I’m unable to reproduce this one with latest build. Can you try version 8.6 to see if the problem remains in current version?

S1854: Issue with local functions was already reported and we have this ticket to track it.