Skip to content

fix(object-creation-mutator): skip empty initializer for required members#3603

Open
slang25 wants to merge 3 commits into
stryker-mutator:masterfrom
slang25:slang25/fix-required-members-cs9035
Open

fix(object-creation-mutator): skip empty initializer for required members#3603
slang25 wants to merge 3 commits into
stryker-mutator:masterfrom
slang25:slang25/fix-required-members-cs9035

Conversation

@slang25

@slang25 slang25 commented May 19, 2026

Copy link
Copy Markdown
Contributor

Summary

  • ObjectCreationMutator always emits an empty-initializer variant (e.g. new Notification {}), which fails to compile with CS9035 when the target type has C# 11 required properties/fields.
  • Use the semantic model to walk the resolved type and its base types; if any member has IsRequired == true, skip the empty-initializer mutation.

Fixes #3598. Split out from #3594.

Test plan

  • Existing ObjectCreationMutatorTests cases still pass
  • New tests cover required property, required field, base-type required member, and a no-required-members baseline that still mutates

…quired members

ObjectCreationMutator always emits an empty-initializer variant
(e.g. `new Notification {}`), which fails to compile with CS9035 when
the target type has C# 11 required properties or fields.

Use the semantic model to walk the resolved type and its base types; if
any member has IsRequired == true, skip the empty-initializer mutation.

Fixes stryker-mutator#3598
Copilot AI review requested due to automatic review settings May 19, 2026 13:36
… skip

Skipping object-initializer mutations on types with required members
removes 4 mutants from the integration target projects.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@dupdob

dupdob commented May 22, 2026

Copy link
Copy Markdown
Member

As said in the related issue, I am afraid I don't think this filtering logic adds enough value to warrant a merge.
But it also gave me an idea:
Overall the intent of Stryker is to maximize the number of significant mutations. As you said elsewhere, Stryker fails to mutate creating of objects/structs/records when they have required members.

Instead of non mutating them, why not using your detection logic to initialize said required members to default value?

I simply wonder if those would be sensible mutations.

What do you think?

…lt! instead of skipping

When the target type has required members, an empty initializer fails to compile
with CS9035. Previously the mutator skipped these creations entirely; now it
emits a mutation that keeps every required member assigned to `default!`,
producing a compileable mutation that still exercises behaviour.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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.

ObjectCreationMutator empty-initializer mutation fails CS9035 on types with required members

2 participants