Skip to content

fix(mutating): avoid uncompilable mutations in several edge cases#3595

Closed
slang25 wants to merge 3 commits into
stryker-mutator:masterfrom
slang25:slang25/review-workspace-changes
Closed

fix(mutating): avoid uncompilable mutations in several edge cases#3595
slang25 wants to merge 3 commits into
stryker-mutator:masterfrom
slang25:slang25/review-workspace-changes

Conversation

@slang25

@slang25 slang25 commented May 19, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Avoid CS0136 by skipping ternary mutation placement when the expression introduces a declaration (e.g. recursive patterns like x is { } v); mutations are forwarded to the enclosing block instead.
  • Include auto-generated compilation trees (e.g. GlobalUsings.g.cs) when building semantic models so mutators that consult the semantic model see resolved types.
  • Restrict LinqMutator to invocations whose receiver implements IEnumerable<T> (or whose containing type is Enumerable/Queryable/ParallelEnumerable), preventing incorrect rewrites of unrelated methods such as IResponseCookies.Append.
  • Skip the ObjectCreationMutator initializer-removal mutation when the target type has any required members (CS9035).

Fixes #3594

Test plan

  • Run existing unit test suite
  • Verify mutation runs against a project using ASP.NET Core (IResponseCookies.Append) no longer produce CS-failure mutants
  • Verify mutation runs against a project using required members no longer produce CS9035 mutants
  • Verify mutation runs against a project using recursive patterns no longer produce CS0136 mutants

…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
Copilot AI review requested due to automatic review settings May 19, 2026 10:45

Copilot AI left a comment

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.

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 LinqMutator to invocations whose receiver implements IEnumerable<T> or whose containing type is Enumerable/Queryable/ParallelEnumerable, falling back to legacy name-only matching when no semantic model is available.
  • Skip the empty-initializer ObjectCreationMutator mutation when the target type (or any base) has required members; promote expression-level mutations to block level when the source expression introduces a declaration (extends ContainsDeclarations to SingleVariableDesignation).
  • 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.

Comment thread src/Stryker.Core/Stryker.Core/Mutators/ObjectCreationMutator.cs Outdated
Comment thread src/Stryker.Core/Stryker.Core/Mutators/ObjectCreationMutator.cs
Comment thread src/Stryker.Core/Stryker.Core/Helpers/RoslynHelper.cs Outdated
slang25 added 2 commits May 19, 2026 11:52
- 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.
Copilot AI review requested due to automatic review settings May 19, 2026 10:57

Copilot AI left a comment

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.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated no new comments.

@slang25

slang25 commented May 19, 2026

Copy link
Copy Markdown
Contributor Author

Closing per maintainer feedback to split into focused PRs. Replaced by:

Bug #2 from the original write-up (CS9234 interceptor cascade) is largely resolved by #3601 in the common case; I've folded it into the #3601 narrative rather than tracking it separately.

@slang25 slang25 closed this May 19, 2026
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.

A handful of Stryker compilation failures on a modern ASP.NET Core (.NET 10) project — with a repro and proposed fixes

2 participants