Skip to content

actionpack: stop typing the abstract render_to_body as nil - #1109

Open
apiology wants to merge 3 commits into
ruby:mainfrom
apiology:actionpack-type-render-to-body
Open

apiology wants to merge 3 commits into
ruby:mainfrom
apiology:actionpack-type-render-to-body

Conversation

@apiology

Copy link
Copy Markdown
Contributor

Claude: This PR was written by Claude Code on behalf of @apiology.

Problem:

The abstract render_to_body is typed nil, though controllers always render a body:

class BodyRenderer
  include AbstractController::Rendering

  def show
    # [error] The branch is unreachable
    render_to_body(template: "show") ? "rendered" : "empty"
  end
end

Tools that type a method from the one it overrides then type every controller's render_to_body as nil, though ActionController::Rendering#render_to_body ends super || _render_in_priorities(options) || " ".

Solution: Declare AbstractController::Rendering#render_to_body, an empty hook its including classes fill in, as returning untyped in actioncontroller.rbs for 7.2 and 8.1, moving its Rails doc out of the generated file.

It returns untyped rather than String because streaming renders return a body object (_render_template). 6.0 is unchanged, per gems/actionpack/README.md.

AbstractController::Rendering#render_to_body is an empty hook: the
including class supplies the body through ActionView::Rendering,
ActionController::Renderers and ActionController::Rendering, and
ActionController::Rendering never returns nil (`super || ... || " "`).
The generated `-> nil` described only the empty default, so tools that
type an override from the method it overrides typed every controller
render_to_body as nil. Streaming renders return a body object rather
than a String, so the hook returns untyped. The declaration and its
Rails doc move to actioncontroller.rbs beside render_to_string.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01SEntZKsZwQHhzqcwG7MTqn
@apiology
apiology marked this pull request as ready for review October 26, 2026 19:15
@github-actions

Copy link
Copy Markdown

@apiology Thanks for your contribution!

Please follow the instructions below for each change.
See also: https://github.com/ruby/gem_rbs_collection/blob/main/docs/CONTRIBUTING.md

Available commands

You can use the following commands by commenting on this PR.

  • /merge: Merge this PR if CI passes

actionpack

You changed RBS files for an existing gem.
You need to get approval from the reviewers of this gem.

@ksss, @tk0miya, please review this pull request.
If this change is acceptable, please make a review comment including APPROVE from here.
Screen Shot 2024-03-19 at 14 13 36

After that, the PR author or the reviewers can merge this PR.
Just comment /merge to merge this PR.

@apiology
apiology marked this pull request as draft October 26, 2026 19:19
The tests sat next to the ones ruby#1115 adds,
so whichever merged second would conflict. At the end of each file
the two PRs touch separate hunks.
@apiology
apiology marked this pull request as ready for review October 29, 2026 23:27
@github-actions

Copy link
Copy Markdown

@apiology Thanks for your contribution!

Please follow the instructions below for each change.
See also: https://github.com/ruby/gem_rbs_collection/blob/main/docs/CONTRIBUTING.md

Available commands

You can use the following commands by commenting on this PR.

  • /merge: Merge this PR if CI passes

actionpack

You changed RBS files for an existing gem.
You need to get approval from the reviewers of this gem.

@ksss, @tk0miya, please review this pull request.
If this change is acceptable, please make a review comment including APPROVE from here.
Screen Shot 2024-03-19 at 14 13 36

After that, the PR author or the reviewers can merge this PR.
Just comment /merge to merge this PR.

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.

1 participant