dotnet/roslyn

Invalid IDE0059 when local.ExtensionMethod used as Delegate

オープン

#42,337 opened on 2020/03/11

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

Repository metrics

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

説明

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());
    }
}

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