stryker-mutator / stryker-net

Mutation testing for .NET core and .NET framework!
https://stryker-mutator.io
Apache License 2.0
1.75k stars 176 forks source link

fix(mutator): issue where non-nullable fields were swapped by NullCoalescingExpressionMutator #2915

Closed ruudschouten closed 1 month ago

ruudschouten commented 2 months ago

Resolves issues with the NullCoalescingExpressionMutator where it tries to create mutations which can never compile, for example;

// request has a nullable EndTime, and a non-nullable StartTime.
node = (request.EndTime ?? request.StartTime)
// The mutator creates three mutators; 
// 1. Swap left and right;  => Only compiles if request.StartTime is Nullable.
(request.StartTime ?? request.EndTime)
// 2. Remove right; => Compiles every time, since this side is always Nullable.
(request.EndTime)
// 3. Remove left  => Only compiles if request.StartTime is Nullable
(request.StartTime)

Mutant 3 resulted in this error being printed in the logs; Safe Mode! Stryker will try to continue by rolling back all mutations in method. This should not happen, please report this as an issue on github with the previous error message.

I have seen a few issues that reported this, which are; fix #2682 fix #2384 fix #2801