Skip to content

Enable nullability for public api#856

Merged
dtchepak merged 9 commits intonsubstitute:mainfrom
Romfos:main
Mar 9, 2025
Merged

Enable nullability for public api#856
dtchepak merged 9 commits intonsubstitute:mainfrom
Romfos:main

Conversation

@Romfos
Copy link
Copy Markdown
Contributor

@Romfos Romfos commented Dec 15, 2024

Changes:

  • (breaking change) Enable nullability for public api
  • Adopt records for some types
  • (breaking change) Obsolete Arg.Compat

related ##830, #551

note: Nullability is still disabled for compatibility for types from "Compatibility" folder

@Romfos Romfos requested a review from dtchepak December 15, 2024 16:40
@Romfos Romfos marked this pull request as ready for review December 15, 2024 16:40
@Romfos Romfos mentioned this pull request Dec 15, 2024
26 tasks
Copy link
Copy Markdown
Member

@dtchepak dtchepak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy for you to merge this as-is. 👍 Thanks!

@Romfos Romfos requested a review from dtchepak February 16, 2025 13:30
@dtchepak dtchepak merged commit 6c37da9 into nsubstitute:main Mar 9, 2025
@dtchepak
Copy link
Copy Markdown
Member

dtchepak commented Mar 9, 2025

Thanks @Romfos !

/// If the <paramref name="predicate"/> throws an exception for an argument it will be treated as non-matching.
/// </summary>
public static ref T Is<T>(Expression<Predicate<T>> predicate)
public static ref T Is<T>(Expression<Predicate<T?>> predicate)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know that it's a bit too late to jump into the train, as it was merged, but I find this change a bit questionable and am concerned about usability of it. For example here now T is nullable, but that's not the case at all. It depends solely on the method we invoke whether the value is null or not. I understand that we don't have a chance to infer that somehow - but yet now people will be forced to use null-forgiving operator. That isn't convenient at all. It's like .ToString()! you have to write all the time - it's annoying and it frankly sucks 😟

The primary purpose of this library is to enable unit testing. I would find it quite surprising that people would have nullability enabled in the unit tests, as.. well, it's unit tests, not the production code and you want to have flexibility there. I could totally see that some are enabling, but yet I wouldn't imagine it being the default.

My primary argument is that we cannot promise nullability or describe anything meaningful - shall we just not enable it for classes like Arg? Like if you don't know the answer to the question - you just say "I don't know" instead of pretending you know something. After this change the compilation could break for the existing test projects (if they have the nullability enabled) and people will have to go and manually suppress it everywhere - isn't it annoying?

@Romfos @dtchepak What are you thoughts on this?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zvirja Thanks for the thoughts. I haven't used C# since nullability changes (mainly Kotlin at the moment), so not across this. This hasn't made it to release so it's fine to revert.

@zvirja
Copy link
Copy Markdown
Contributor

zvirja commented Mar 10, 2025

@Romfos And maybe one more question to better understand the context - what is the practical problem we are solving with this change? Was it a request from customers or you faced personally some usability issues due to missing annotations for configuration API?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants