dotnet/roslyn

Invalid IDE0059 when local.ExtensionMethod used as Delegate

開放

#42,337 建立於 2020年3月11日

 (1 則留言) (0 個反應) (0 位負責人)C# (4,257 個分叉)batch import
Area-IDEBugFeature - IDE0059help wanted

倉庫指標

星標
 (20,414 顆星)
PR 合併指標
 (平均合併 6天 17小時) (30 天內合併 256 個 PR)

描述

Version Used: master as of the 10th march

Steps to Reproduce:

using System;
public static class Program {
    public static void Main() {
        var x = 42;
        Func<string> a = x.ToStringExt;
        Console.WriteLine(a());
    }
    
    public static string ToStringExt(this object x) => x.ToString();
}

Expected Behavior: No warning.

Actual Behavior: IDE0059 unnecessary assignment of a value to 'x' Also the suggested codefix 'remove redundant assignment' doesn't compile:

using System;
public static class Program {
    public static void Main() {
        int x;
        Func<string> a = () => x.ToString(); // error CS0165: Use of unassigned local variable 'x'
        Console.WriteLine(a());
    }
}

貢獻者指南