Skip to content

Ambiguity errors reported from SemanticModel.GetDiagnostics() for calls to partial members on type with primary constructor #75002

Closed
@cston

Description

@cston

Version Used: 2ff1a47

Steps to Reproduce:

Run the following unit test.

[Fact]
public void PartialMembers()
{
    var source1 = """
        C c = null;
        c.M();
        _ = c.P;
        """;
    var source2 = """
        partial class C(int p)
        {
            public partial void M() { }
            public partial void M();
            public partial object P { get; }
            public partial object P { get => null; }
        }
        """;
    var comp = CreateCompilation([source1, source2]);
    var tree = comp.SyntaxTrees[0];
    var model = comp.GetSemanticModel(tree);
    model.GetDiagnostics().Verify(
        // (2,3): error CS0121: The call is ambiguous between the following methods or properties: 'C.M()' and 'C.M()'
        // c.M();
        Diagnostic(ErrorCode.ERR_AmbigCall, "M").WithArguments("C.M()", "C.M()").WithLocation(2, 3),
        // (3,7): error CS0229: Ambiguity between 'C.P' and 'C.P'
        // _ = c.P;
        Diagnostic(ErrorCode.ERR_AmbigMember, "P").WithArguments("C.P", "C.P").WithLocation(3, 7));
}

Expected Behavior:
No errors from the call to model.GetDiagnostics().

Actual Behavior:
Ambiguity errors included above.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions