fix: flip equality comparisons in place instead of calling a generic helper - #45
Merged
Conversation
…helper Go permits x == y between operands of different static types when one is assignable to the other (e.g. any == error, io.Writer == *os.File, or two interface types where one embeds the other). The generated generic helper _mutest_eq_N[T comparable](a, b T) cannot unify such operands into a single type parameter, so type inference failed and the whole package aborted at the build stage with zero results (issue #39). Since the equality mutation is exactly a negation, rewrite the site as (x == y) != _mutest_on(N) where _mutest_on reports whether mutant N is active. The original comparison stays in place, evaluated once, so its typing and semantics cannot drift: - mixed static types need no inference (fixes #39) - comparison results stay untyped bool, so defined-bool-type contexts (type Flag bool; return a == b) now build too, where the old helper's typed bool aborted the package the same way - recover() in an operand keeps working: unlike the inline closure previously used for nil comparisons, the operand is not moved into a nested function literal, where recover() no longer stops a panic - operand text is emitted once, so nested equality grows linearly This replaces both the _mutest_eq_N helper and the nil-comparison inline closure. Ordered comparisons keep the generic cmp.Ordered helper: their mutations are not negations. instrumentFile now also fails loudly if a mutation point matches no AST node instead of silently reporting a no-op mutant as SURVIVED. Fixes #39
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.
Go permits x == y between operands of different static types when one is
assignable to the other (e.g. any == error, io.Writer == *os.File, or two
interface types where one embeds the other). The generated generic helper
_mutest_eq_N[T comparable](a, b T) cannot unify such operands into a single
type parameter, so type inference failed and the whole package aborted at
the build stage with zero results (issue #39).
Since the equality mutation is exactly a negation, rewrite the site as
where _mutest_on reports whether mutant N is active. The original
comparison stays in place, evaluated once, so its typing and semantics
cannot drift:
(type Flag bool; return a == b) now build too, where the old helper's
typed bool aborted the package the same way
previously used for nil comparisons, the operand is not moved into a
nested function literal, where recover() no longer stops a panic
This replaces both the _mutest_eq_N helper and the nil-comparison inline
closure. Ordered comparisons keep the generic cmp.Ordered helper: their
mutations are not negations. instrumentFile now also fails loudly if a
mutation point matches no AST node instead of silently reporting a no-op
mutant as SURVIVED.
Fixes #39