Skip to content

An expected warning about an obsolete override is missing when overridden method is defined in a generic type. #81937

@AlekseyTs

Description

@AlekseyTs

The following test fails due to a missing warning. The warning is reported when C0 is not generic.

        [Fact]
        public void ObsoleteOverrideChain_02()
        {
            string source1 = @"
using System;

public class C0<T>
{
    public virtual void M(){}
}

public class C1<T> : C0<T>
{
    [Obsolete]
    public override void M(){}
}
";
            var comp1 = CreateCompilation(source1);

            string source2 = @"
using System;

internal class C2 {}

internal class C3: C1<C2>
{
    [Obsolete]
    public override void M() { }
}
";

            var comp2 = CreateCompilation(source2, references: [comp1.ToMetadataReference()]);
            comp2.VerifyDiagnostics(
                // (9,26): warning CS0809: Obsolete member 'C3.M()' overrides non-obsolete member 'C0.M()'
                //     public override void M() { }
                Diagnostic(ErrorCode.WRN_ObsoleteOverridingNonObsolete, "M").WithArguments("C3.M()", "C0.M()").WithLocation(9, 26)
                );
        }

Metadata

Metadata

Type

No fields configured for Bug.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions