Skip to content

Constrain the callback of the sum-case transform and transform_error#297

Merged
Bronek merged 2 commits into
mainfrom
bronek/P3/sum_transform_constraints
Jul 13, 2026
Merged

Constrain the callback of the sum-case transform and transform_error#297
Bronek merged 2 commits into
mainfrom
bronek/P3/sum_transform_constraints

Conversation

@Bronek

@Bronek Bronek commented Jul 13, 2026

Copy link
Copy Markdown
Member

Two missing conjuncts in the constraints of the monadic statics, both leaving a failure to be discovered inside the deduced-return body instead of the immediate context.

Constrain the callback of the sum-case transform and transform_error

The sum-delegating statics constrained only the grade, leaving callback validity to be discovered inside the deduced-return body. Two consequences, both outside the immediate context: a callback no alternative could take was a hard error where the non-sum path cleanly drops the candidate, and overload resolution was poisoned - the losing const & candidate formed its signature too, so a visitor serving only the category the call selects made the call ill-formed.

Constraining the callback in the immediate context, as sum::transform itself does, means a partial visitor is now enough. The existing tests spell all four value categories in every visitor because they had to; the new blocks assert they no longer do.

Require of transform_error that the untouched value can be relocated

The body puts the untouched value into the result, but only the noexcept spec weighed that copy - the requires-clause did not, alone among the monadic statics (_or_else, _and_then and _transform all carry their untouched-side conjunct). The copy was therefore checked while instantiating the deduced-return body, and since const & binds rvalues, the losing candidate hard-errored for a move-only value type: fn::expected<move_only, E> could not call transform_error from any value category, where pfn::expected supports the rvalue call and cleanly drops the lvalue one. A pfn -> fn switch turned valid code ill-formed.

Closes #277
Closes #278


Stack: P3 of 13 — the release-0.1 bugfix queue, merging bottom-up into main. Based on #296 and to be retargeted to main once it merges; the diff shows only this PR's commits. Every stack boundary was validated with a gcc build and the full test suite on top of main, and the aggregate branch ran the full CI matrix green (#289).

@augmentcode

augmentcode Bot commented Jul 13, 2026

Copy link
Copy Markdown
🤖 Augment PR Summary

Summary: Tightens the immediate-context constraints for sum-delegating monadic statics so invalid callbacks are rejected via constraints (dropping non-viable overloads) rather than failing during deduced-return body instantiation.

Changes:

  • Constrained sum-case expected::_transform and expected::_transform_error with fn::detail::_typelist_invocable to ensure the callback is viable for the selected value category.
  • Applied the same immediate-context callback constraint to sum-case optional::_transform.
  • Added a missing “untouched value can be relocated” conjunct to expected::_transform_error so move-only value types correctly drop copying overloads.
  • Extended tests to assert the new constraint behavior (partial visitors by value category, and move-only relocation semantics).

Technical Notes: This addresses overload-resolution poisoning and hard errors from failures discovered only inside deduced-return bodies, aligning behavior with other monadic helpers and pfn compatibility.

🤖 Was this summary useful? React with 👍 or 👎

@augmentcode augmentcode Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. No suggestions at this time.

Comment augment review to trigger a new review at any time.

@Bronek Bronek force-pushed the bronek/P2/in_place_type_constraints branch from ad37ed3 to a8019a3 Compare July 13, 2026 11:10
@Bronek Bronek changed the base branch from bronek/P2/in_place_type_constraints to main July 13, 2026 11:50
Bronek added 2 commits July 13, 2026 12:52
The sum-delegating statics constrained only the grade, leaving callback validity to
be discovered inside the deduced-return body. Two consequences, both outside the
immediate context: a callback no alternative could take was a hard error where the
non-sum path cleanly drops the candidate, and overload resolution was poisoned -
the losing `const &` candidate formed its signature too, so a visitor serving only
the category the call selects made the call ill-formed.

Constraining the callback in the immediate context, as `sum::transform` itself does,
means a partial visitor is now enough. The existing tests spell all four value
categories in every visitor because they had to; the new blocks assert they no
longer do.

Closes #277

Assisted-by: Claude:claude-opus-4-8[1m]
The body puts the untouched value into the result, but only the noexcept spec
weighed that copy - the requires-clause did not, alone among the monadic statics
(`_or_else`, `_and_then` and `_transform` all carry their untouched-side conjunct).
The copy was therefore checked while instantiating the deduced-return body, and
since `const &` binds rvalues, the losing candidate hard-errored for a move-only
value type: `fn::expected<move_only, E>` could not call `transform_error` from any
value category, where `pfn::expected` supports the rvalue call and cleanly drops
the lvalue one. A pfn -> fn switch turned valid code ill-formed.

Closes #278

Assisted-by: Claude:claude-opus-4-8[1m]
@Bronek Bronek force-pushed the bronek/P3/sum_transform_constraints branch from 3acb5e5 to 23c55fa Compare July 13, 2026 11:53
@Bronek

Bronek commented Jul 13, 2026

Copy link
Copy Markdown
Member Author

augment review

@augmentcode augmentcode Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. No suggestions at this time.

Comment augment review to trigger a new review at any time.

@sonarqubecloud

Copy link
Copy Markdown

@codecov

codecov Bot commented Jul 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@Bronek Bronek merged commit d5c6bb2 into main Jul 13, 2026
64 checks passed
Bronek added a commit that referenced this pull request Jul 13, 2026
Take #297's new constraint sections for the sum-case transform and
transform_error, and retire the GAP notes they answer. Both defects were
hard errors, so the suite could only describe them in comments: a callback
no alternative accepts now drops the candidate, a visitor need only serve
the category the call selects, and a move-only value drops the copying
overloads. Main's blocks land as SECTIONs, keeping the suite free of the
BDD macros.

Assisted-by: Claude:claude-opus-4-8[1m]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant