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

[release/7.0-rc1] Fix nullable annotations on generic math interfaces #74116

Merged
merged 2 commits into from
Aug 18, 2022

Commits on Aug 18, 2022

  1. Fix nullable annotations on generic math interfaces

    - All `where TSelf : ...` constraints become `where TSelf : ...?`.  Without this, trying to define a type like `Matrix<T> where T : INumber<T>?` in order to support nullable T types warns because `INumber<T>` constrains its `T` (`TSelf`) to be non-nullable.
    - All `where TOther : ...` constraints are changed to be oblivious. They can't be correctly annotated as there's no way to express the nullability relationship with the nullability of TSelf.
    - Use `[MaybeNullWhen(false)] out T` instead of `[NotNullWhen(true)] out T?`, as we do with other generics, since if the instantiation of `T` is nullable, we can't guarantee `NotNullWhen(true)`.
    - Make `IEqualityOperators` `==` and `!=` accept `TSelf?`. This keeps it consistent with `IEquatable<T>.Equals(T?)`, `IEqualityComparer<in T>.Equals(T?, T?)`, `IEqualityComparer.Equals(object?, object?)`, `IStructuralEquatable.Equals(object?, IEqualityComparer)`, and `object.Equals(object?)` which all allow null even if generic and the generic is non-null. It in turn enables checks like `T.Zero == default` without nullability warnings.
    stephentoub authored and github-actions committed Aug 18, 2022
    Configuration menu
    Copy the full SHA
    8039e70 View commit details
    Browse the repository at this point in the history
  2. Address PR feedback

    stephentoub authored and github-actions committed Aug 18, 2022
    Configuration menu
    Copy the full SHA
    cfe408e View commit details
    Browse the repository at this point in the history