Skip to content

Type parameters declared in disabled context should have oblivious nullability #29980

@AlekseyTs

Description

@AlekseyTs
        [Fact]
        public void Constraints_65()
        {
            var source =
@"
#nullable disable 
interface I1
{
    void F1<TF1>();
}

#nullabe enable 
class A : I1
{
    public void F1<TF1A>() where TF1A : object
    {}
}
";
            var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition });
            // PROTOTYPE(NullableReferenceTypes): unexpected warning
            comp.VerifyDiagnostics(
                // (21,17): warning CS8633: Nullability in constraints for type parameter 'TF1A' of method 'A.F1<TF1A>()' doesn't match the constraints for type parameter 'TF1' of interface method 'I1.F1<TF1>()'. Consider using an explicit interface implementation instead.
                //     public void F1<TF1A>() where TF1A : object
                Diagnostic(ErrorCode.WRN_NullabilityMismatchInConstraintsOnImplicitImplementation, "F1").WithArguments("TF1A", "A.F1<TF1A>()", "TF1", "I1.F1<TF1>()").WithLocation(21, 17)
                );
        }

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions