dotnet/roslyn

IDE0059 is triggered for recurrent lambda initialization

オープン

#48,622 opened on 2020/10/15

 (0 件のコメント) (0 件のリアクション) (1 人の担当者)C# (4,257 件のフォーク)batch import
Area-AnalyzersBugFeature - IDE0059help wanted

Repository metrics

Stars
 (20,414 個のスター)
PR merge metrics
 (平均マージ 6d 17h) (30d で 256 merged PRs)

説明

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.

コントリビューターガイド