dotnet/roslyn

IDE0059 is triggered for recurrent lambda initialization

Offen

#48.622 geöffnet am 15.10.2020

 (0 Kommentare) (0 Reaktionen) (1 zugewiesene Person)C# (4.257 Forks)batch import
Area-AnalyzersBugFeature - IDE0059help wanted

Repository-Metriken

Stars
 (20.414 Sterne)
PR-Merge-Metriken
 (Durchschn. Merge 6T 17h) (256 gemergte PRs in 30 T)

Beschreibung

Version Used: VS 16.9.0 Preview 1.0 [30609.169.main]

Steps to Reproduce:

using System;

namespace TestNamespace
{
    public class TestClass
    {
        public void TestMethod()
        {
            Func<string, string> func = null;
            func = s =>
            {
                // When initialization above is removed, this line results in an error:
                // Use of unassigned local variable 'func'
                return func(s);
            };
        }
    }
}

Expected Behavior: IDE0059 should not be triggered for func.

Actual Behavior: IDE0059 is triggered for func but when initialization to null is removed, compiler raises error:

Use of unassigned local variable 'func'

For the return func(s); line.

Contributor Guide