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

APICompat should warn for nullable-enabled implementation of nullable-disabled base member #35667

Open
sharwell opened this issue Sep 22, 2023 · 2 comments

Comments

@sharwell
Copy link
Member

sharwell commented Sep 22, 2023

Describe the bug

ApiCompat fails to warn users when they expose a nullable-enabled implementation of a member which is not nullable-enabled. This can lead to errors in the future if the base member becomes null-annotated in a way which is not compatible with the implementing signature.

Special cases to consider:

  1. If the return type of the implementation is declared non-nullable, there may be no need to create a warning. Even if the base type is updated to return a nullable type, the implementation is allowed to further constrain the value to non-null.
    • Note that if the implementation includes a line that returns the result of calling the base member, a change to the base signature might necessitate a change to the implementation signature, so the warning might still be valuable.
  2. If the type of a parameter is declared nullable, there may be no need to create a warning. Even if the base type is updated to only accept a non-nullable type, the implementation is allowed to further relax the value to nullable.
    • Note that if the implementation includes a call to the base member and passes the parameter value, a change to the base signature might necessitate a change to the implementation signature, so the warning might still be valuable.

To Reproduce

#nullable disable

internal class BaseType
{
    protected virtual void Method(object obj) { }
}

#nullable enable

internal class DerivedType : BaseType
{
    protected override void Method(object obj) { }
}
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-ApiCompat untriaged Request triage from a team member labels Sep 22, 2023
@ghost
Copy link

ghost commented Sep 22, 2023

@dotnet/area-infrastructure-libraries a new issue has been filed in the ApiCompat area, please triage

@ericstj
Copy link
Member

ericstj commented Sep 22, 2023

This should be covered as part of #18681

@ViktorHofer ViktorHofer removed the untriaged Request triage from a team member label Mar 10, 2025
@ViktorHofer ViktorHofer added this to the Backlog milestone Mar 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants