fix(mutating): avoid uncompilable mutations in several edge cases#3595
Closed
slang25 wants to merge 3 commits into
Closed
fix(mutating): avoid uncompilable mutations in several edge cases#3595slang25 wants to merge 3 commits into
slang25 wants to merge 3 commits into
Conversation
…e cases
- Skip ternary placement for expressions introducing declarations
(e.g. recursive patterns `x is { } v`) to avoid CS0136.
- Include auto-generated compilation trees in semantic models so
implicit usings and attributes resolve correctly.
- Restrict LINQ mutations to invocations whose receiver actually
implements IEnumerable<T>, preventing rewrites of unrelated methods
like IResponseCookies.Append.
- Skip object initializer removal when the target type has required
members (CS9035).
Fixes stryker-mutator#3594
Contributor
There was a problem hiding this comment.
Pull request overview
Targeted fixes for four edge cases that caused Stryker to generate uncompilable mutants on modern ASP.NET Core / .NET 10 projects (issue #3594). The changes make several mutators consult the semantic model more carefully and feed it the auto-generated trees it needs (e.g. GlobalUsings.g.cs) so that implicit-using-based types resolve correctly.
Changes:
- Restrict
LinqMutatorto invocations whose receiver implementsIEnumerable<T>or whose containing type isEnumerable/Queryable/ParallelEnumerable, falling back to legacy name-only matching when no semantic model is available. - Skip the empty-initializer
ObjectCreationMutatormutation when the target type (or any base) hasrequiredmembers; promote expression-level mutations to block level when the source expression introduces a declaration (extendsContainsDeclarationstoSingleVariableDesignation). - Include the project's
CompilationSyntaxTrees(alongside file trees) when building the semantic models used during mutation.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Stryker.Core/Stryker.Core/Mutators/ObjectCreationMutator.cs | Skip empty-initializer mutation when the type has required members. |
| src/Stryker.Core/Stryker.Core/Mutators/LinqMutator.cs | Gate LINQ mutations on receiver type / LINQ host type via semantic model. |
| src/Stryker.Core/Stryker.Core/MutationTest/CsharpMutationProcess.cs | Add auto-generated trees to the semantic models used during mutation. |
| src/Stryker.Core/Stryker.Core/Mutants/MutationStore.cs | Forward expression mutations to enclosing block when source introduces a declaration. |
| src/Stryker.Core/Stryker.Core/Helpers/RoslynHelper.cs | Treat SingleVariableDesignation as a declaration for ternary-control checks. |
- Fix comment: error is CS9035, not CS8852. - Scope SingleVariableDesignation declaration check to designations under RecursivePatternSyntax/VarPatternSyntax so unrelated designations (out var, tuple deconstruction, list patterns) keep their previous expression-level mutation behaviour. - Add unit tests for ObjectCreationMutator required-member skip, LinqMutator semantic gate on non-IEnumerable receivers, and RoslynHelper.ContainsDeclarations pattern designations.
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
x is { } v); mutations are forwarded to the enclosing block instead.GlobalUsings.g.cs) when building semantic models so mutators that consult the semantic model see resolved types.LinqMutatorto invocations whose receiver implementsIEnumerable<T>(or whose containing type isEnumerable/Queryable/ParallelEnumerable), preventing incorrect rewrites of unrelated methods such asIResponseCookies.Append.ObjectCreationMutatorinitializer-removal mutation when the target type has anyrequiredmembers (CS9035).Fixes #3594
Test plan
IResponseCookies.Append) no longer produce CS-failure mutantsrequiredmembers no longer produce CS9035 mutants