Skip to content

CRef utilizing an operator syntax can resolve against a regular method with matching special name #78103

Open
@AlekseyTs

Description

@AlekseyTs

Note that the opposite (resolving a named reference against an operator) can happen as well. Need to confirm whether this is a desired behavior or an oversite.

The following unit tests succeed

        [Theory]
        [CombinatorialData]
        public void Increment_114_CRef([CombinatorialValues("++", "--")] string op)
        {
            var source = @"
/// <summary>
/// See <see cref=""operator " + op + @"""/>.
/// </summary>
class C1
{
    public static C1 " + (op == "++" ? WellKnownMemberNames.IncrementOperatorName : WellKnownMemberNames.DecrementOperatorName) + @"() => null;
}

/// <summary>
/// See <see cref=""C1.operator " + op + @"""/>.
/// </summary>
class C2
{}
";
            var compilation = CreateCompilationWithMscorlib40AndDocumentationComments(source, parseOptions: TestOptions.RegularPreview.WithDocumentationMode(DocumentationMode.Diagnose));
            compilation.VerifyDiagnostics();

            int count = 0;
            foreach (var crefSyntax in GetCrefSyntaxes(compilation))
            {
                var actualSymbol = GetReferencedSymbol(crefSyntax, compilation);
                AssertEx.Equal("C1." + (op == "++" ? WellKnownMemberNames.IncrementOperatorName : WellKnownMemberNames.DecrementOperatorName) + @"()", actualSymbol.ToDisplayString());
                count++;
            }

            Assert.Equal(2, count);
        }

        [Theory]
        [CombinatorialData]
        public void Increment_115_CRef([CombinatorialValues("++", "--")] string op)
        {
            var source = @"
/// <summary>
/// See <see cref=""" + (op == "++" ? WellKnownMemberNames.IncrementOperatorName : WellKnownMemberNames.DecrementOperatorName) + @"""/>.
/// </summary>
class C1
{
    public static C1 operator " + op + @"(C1 x) => x;
}

/// <summary>
/// See <see cref=""C1." + (op == "++" ? WellKnownMemberNames.IncrementOperatorName : WellKnownMemberNames.DecrementOperatorName) + @"""/>.
/// </summary>
class C2
{}
";
            var compilation = CreateCompilationWithMscorlib40AndDocumentationComments(source, parseOptions: TestOptions.RegularPreview.WithDocumentationMode(DocumentationMode.Diagnose));
            compilation.VerifyDiagnostics();

            int count = 0;
            foreach (var crefSyntax in GetCrefSyntaxes(compilation))
            {
                var actualSymbol = GetReferencedSymbol(crefSyntax, compilation);
                AssertEx.Equal("C1.operator " + op + @"(C1)", actualSymbol.ToDisplayString());
                count++;
            }

            Assert.Equal(2, count);
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-CompilersuntriagedIssues and PRs which have not yet been triaged by a lead

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions