Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OverloadResolutionPriority is not respected on some attribute constructors #75985

Open
AlekseyTs opened this issue Nov 20, 2024 · 3 comments
Open
Labels
Area-Compilers Feature - Overload Resolution Priority untriaged Issues and PRs which have not yet been triaged by a lead
Milestone

Comments

@AlekseyTs
Copy link
Contributor

The unit-tests reflect the current behavior:

    [Fact]
    public void CycleOnOverloadResolutionPriorityConstructor_07()
    {
        var source = """
            using System.Runtime.CompilerServices;

            namespace System
            {
                public class ObsoleteAttribute : Attribute
                {
                    public ObsoleteAttribute(string x){}

                    [OverloadResolutionPriority(1)]
                    public ObsoleteAttribute(string x, bool y = false){}

                }
            }

            #pragma warning disable CS0436 // The type 'ObsoleteAttribute' in '' conflicts with the imported type 'ObsoleteAttribute'

            [System.Obsolete("Test")]
            public class C {}
            
            public class D
            {
                public C x;
            }
            """;

        var verifier = CompileAndVerify([source, OverloadResolutionPriorityAttributeDefinition],
            symbolValidator: (m) =>
            {
                AssertEx.Equal("System.ObsoleteAttribute..ctor(System.String x)",
                               m.ContainingAssembly.GetTypeByMetadataName("C")!.GetAttributes().Single().AttributeConstructor.ToTestDisplayString());
            });
        verifier.VerifyDiagnostics(
            // (22,12): warning CS0618: 'C' is obsolete: 'Test'
            //     public C x;
            Diagnostic(ErrorCode.WRN_DeprecatedSymbolStr, "C").WithArguments("C", "Test").WithLocation(22, 12)
            );
    }

    [Fact]
    public void CycleOnOverloadResolutionPriorityConstructor_08()
    {
        var source = """
            using System.Runtime.CompilerServices;

            namespace System
            {
                public class ObsoleteAttribute : Attribute
                {
                    public ObsoleteAttribute(string x){}

                    [OverloadResolutionPriority(1)]
                    public ObsoleteAttribute(string x, bool y = true){}

                }
            }

            #pragma warning disable CS0436 // The type 'ObsoleteAttribute' in '' conflicts with the imported type 'ObsoleteAttribute'

            [System.Obsolete("Test")]
            public class C {}
            
            public class D
            {
                public C x;
            }
            """;

        var verifier = CompileAndVerify([source, OverloadResolutionPriorityAttributeDefinition],
            symbolValidator: (m) =>
            {
                AssertEx.Equal("System.ObsoleteAttribute..ctor(System.String x)",
                               m.ContainingAssembly.GetTypeByMetadataName("C")!.GetAttributes().Single().AttributeConstructor.ToTestDisplayString());
            });
        verifier.VerifyDiagnostics(
            // (22,12): warning CS0618: 'C' is obsolete: 'Test'
            //     public C x;
            Diagnostic(ErrorCode.WRN_DeprecatedSymbolStr, "C").WithArguments("C", "Test").WithLocation(22, 12)
            );
    }

Observed:
[System.Obsolete("Test")] binds to System.ObsoleteAttribute..ctor(System.String x)

Expected:
[System.Obsolete("Test")] binds to System.ObsoleteAttribute..ctor(System.String x, System.Boolean y)

@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged Issues and PRs which have not yet been triaged by a lead label Nov 20, 2024
@AlekseyTs
Copy link
Contributor Author

@333fred FYI

@333fred
Copy link
Member

333fred commented Nov 20, 2024

Yes, that's the behavior I expected to see.

talks about this, and points to the test that shows the behavior.

@AlekseyTs
Copy link
Contributor Author

Yes, that's the behavior I expected to see.

I don't think it has to be this way though. That is why I opened the issue. We can talk offline in more details.

@jaredpar jaredpar added this to the 17.13 milestone Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Feature - Overload Resolution Priority untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

No branches or pull requests

3 participants