dotnet/roslyn

IDE0059 is triggered for recurrent lambda initialization

开放

#48,622 创建于 2020年10月15日

 (0 条评论) (0 个反应) (1 位负责人)C# (4,257 个派生)batch import
Area-AnalyzersBugFeature - IDE0059help wanted

仓库指标

星标
 (20,414 个星标)
PR 合并指标
 (平均合并 6天 17小时) (30 天内合并 256 个 PR)

描述

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.

贡献者指南