dotnet/roslyn

IDE0059 generates ambiguity errors for overloads with `out`

开放

#38,053 创建于 2019年8月16日

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

仓库指标

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

描述

Version Used: 3.3.0-beta3-19413-06+ac06df1bffb7b7fd0e5bf63cc91921af76b21e03

Steps to Reproduce:

class Program
{
    static void Main()
    {
        string s;
        Foo(out s);

        int i;
        Foo(out i);
    }

    static void Foo(out int blah) => blah = 0;
    static void Foo(out string blah) => blah = "";
}

Fix All for IDE0059.

Expected Behavior: IDE0059 shouldn't be offered, or if it is, the generated code should employ some disambiguation mechanism.

Actual Behavior:

class Program
{
    static void Main()
    {
        Foo(out _);
        Foo(out _);
    }

    static void Foo(out int blah) => blah = 0;
    static void Foo(out string blah) => blah = "";
}

which fails to compile:

1>Program.cs(5,9,5,12): error CS0121: The call is ambiguous between the following methods or properties: 'Program.Foo(out int)' and 'Program.Foo(out string)'
1>Program.cs(6,9,6,12): error CS0121: The call is ambiguous between the following methods or properties: 'Program.Foo(out int)' and 'Program.Foo(out string)'

贡献者指南