MutagenEx.Mutators.WithSwap (mutagen_ex v0.2.0)

Copy Markdown View Source

Reorders the first two <- clauses of a with expression.

Per mutagen.mutators catalog entry 5.

The two arrows must lead the with. Later clauses and the do and else blocks stay in place.

Only independent clauses qualify for the failure-priority filters below. Treat the clauses as dependent if a name bound by either pattern appears anywhere in the other clause, or either clause uses lexical introspection such as binding(), dbg() or __ENV__.

For the existing use-before-bind check, a variable-shaped name in the moved-first RHS that the moved-second pattern binds returns {:skip, :bound_var_used_before_binding}. This name scan ignores module attributes and binary modifiers. It can skip valid swaps when an outer binding supplies the name or the occurrence is local to a nested fn, case, for, receive, rescue, with, match?, match or destructure, or just quoted data. The compiler resolves dependencies in pins, guards and binary sizes when the swap is kept.

For independent clauses, validation returns:

  • :insufficient_refutable_patterns if either arrow always matches by syntax: an unguarded variable or wildcard, or a literal pattern with an identical literal expression.
  • :indistinguishable_failures if both expressions are the same literal or read the same variable.

Unexpanded macros can hide reads, bindings and effects. The filters can miss swaps that only change side effects or exceptions, and kept swaps can still be equivalent.