You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Arg.Is<T> forces Predicate<T?> even for non-nullable T causing CS8602 and CS8604 at every call #973
Since the nullable annotations work in #856, Arg.Is has this signature: public static ref T Is<T>(Expression<Predicate<T?>> predicate)
Because the predicate parameter is unconditionally T?, the compiler treats the lambda parameter as possibly-null even when T is a non-nullable reference type. In practice this means: substitute.DoSomething(Arg.Is<Foo>(foo => foo.Bar == "baz"));
now produces CS8602 on foo.Bar, even though the method under test (DoSomething(Foo foo)) never accepts null for that parameter. The same shows up as CS8604 when the matched value is passed onward to something expecting non-null T.
I can understand the need for null-matching, Arg.Is has to support matching literal null for reference types: Arg.Is<string>(x => x == null)
The problem is that now this one case makes every Arg.Is call nullable, instead of only the ones that actually care about null.
I would keep Arg.Is(Expression<Predicate> predicate) non-nullable by default, so that the common case has no errors and introduce a seperate item for null-matching, something like: public static ref T IsPossibleNull<T>(Expression<Predicate<T?>> predicate)
This keeps the normal case clean and makes the null-matching explicit instead of every test project having to blanket-suppress CS8602/CS8604 after upgrading to 6.0.
Reacted by VincenRoy, Benoit Carrier, David O'Rourke, OllieOptix, Samuel Veillette, Glen Stone, blaine-grady-poppulo, Pavel Pachobut, Günther Foidl, Lennart Brüggemann and 16 more
I am also running into this issue while trying to upgrade to 6.0.0. It looks like this problem with Arg.Is was mentioned in the comments of #856 and there was talk of reverting it but that didn't happen.
I also ran into this while upgrading to v6. Our project has a very strict policy and uses WarningsAsErrors for everything nullability-related. As such, this change broke our build and with thousands of instances of this, it's unfeasibly tedious to update. If this change would actually make sense then it could be worth it, but I don't see the point in having to null-check something that is already "guaranteed" not-null at compile-time.
In cases where it can be null, I'm already using Arg.Is<MyClass?>(...). There was no problem to be solved here, I don't understand the point of this change.
What makes it even worse is that Arg.Is takes an Expression, and expression-trees cannot contain null-chaining, so now I'm required to use null-enforcement ! in every use of Arg.Is with a predicate (ouch!).
For these reasons, I really hope the proposed fix here will get accepted :)
btw, a similar issue exists for CallInfo.Arg now, which always returns nullable, even when given a non-nullable T. Would you like to solve that as part of the same PR, or prefer me to describe it in a separate issue?
Activity
stogle commentedon Jul 13, 2026
I am also running into this issue while trying to upgrade to 6.0.0. It looks like this problem with
Arg.Iswas mentioned in the comments of #856 and there was talk of reverting it but that didn't happen.jdb0123 commentedon Jul 13, 2026
@Romfos
I believe the fixes should be a bit wider than #975
I created #976
Still work in progress
Wabelbit commentedon Jul 30, 2026
I also ran into this while upgrading to v6. Our project has a very strict policy and uses WarningsAsErrors for everything nullability-related. As such, this change broke our build and with thousands of instances of this, it's unfeasibly tedious to update. If this change would actually make sense then it could be worth it, but I don't see the point in having to null-check something that is already "guaranteed" not-null at compile-time.
In cases where it can be null, I'm already using
Arg.Is<MyClass?>(...). There was no problem to be solved here, I don't understand the point of this change.What makes it even worse is that
Arg.Istakes anExpression, and expression-trees cannot contain null-chaining, so now I'm required to use null-enforcement!in every use ofArg.Iswith a predicate (ouch!).For these reasons, I really hope the proposed fix here will get accepted :)
Wabelbit commentedon Jul 30, 2026
btw, a similar issue exists for
CallInfo.Argnow, which always returns nullable, even when given a non-nullable T. Would you like to solve that as part of the same PR, or prefer me to describe it in a separate issue?cremor commentedon Jul 30, 2026
See the discussion in #976
fix(deps): hold NSubstitute at 5.3.0 pending 6.0.1
fix(deps): hold NSubstitute at 5.3.0 pending 6.0.1
fix(deps): hold NSubstitute at 5.3.0 pending 6.0.1
zvirja commentedon Aug 8, 2026
We reverted nullability annotations in v6.1, so it shall no longer be an issue.