Skip to content

Auto-skip equivalent mutants in clamp patterns (if x < C { x = C }) #43

Description

@fchimpan

Summary

Found while dogfooding mutest v0.6.0 (e6eca1b) against a real-world Go codebase (commit eb6320af). The clamp idiom produces a provably unkillable mutant:

// private/pkg/thread/thread.go:43 — reported SURVIVED
if parallelism < 1 {
    parallelism = 1
}

Mutating < to <= is equivalent for every input:

  • x < 1: both clamp to 1
  • x == 1: original does nothing, mutant assigns 1 — same result
  • x > 1: neither fires

No test can ever kill this mutant, so it is guaranteed noise in every run, which conflicts with the project goal that every surviving mutant should represent a real test gap.

Proposal

Skip the boundary mutation when an if statement matches the clamp shape:

  • Cond is x OP C with OP in <, <=, >, >= (either operand order)
  • Body is exactly one assignment x = C where x and C are syntactically identical to the condition operands

Since the comparison mutator only swaps strict/non-strict operators, matching this shape can drop the mutation point entirely, same as the existing len(x) > 0 / cap(x) > 0 skips documented in "Skipped Mutations".

Notes

Variants worth covering: if C > x { x = C } (swapped operands) and max-clamps if x > C { x = C }. Patterns where the assigned value differs from the compared constant (e.g. if x < 0 { x = 1 }) are NOT equivalent and must stay mutated.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions