Skip to content

sorbet: remove redundant T.let in initialize methods#21990

Merged
dduugg merged 1 commit intomainfrom
dug/sorbet-remove-redundant-tlet
Apr 11, 2026
Merged

sorbet: remove redundant T.let in initialize methods#21990
dduugg merged 1 commit intomainfrom
dug/sorbet-remove-redundant-tlet

Conversation

@dduugg
Copy link
Copy Markdown
Member

@dduugg dduugg commented Apr 10, 2026

Remove T.let calls in initialize methods where the ivar is assigned directly from a sig-typed parameter with an identical type. Sorbet already infers the ivar type from the sig, so the T.let is redundant.

16 files affected. Cases where T.let is still required were left untouched:

  • Chain assignments (specs[:x] = @x = T.let(...)) in cask/url.rb — Sorbet requires explicit T.let for ivars in typed: strict here
  • Conditionally-assigned ivars (locale.rb, cmd/update-report.rb) — T.let sets the nilable type
  • Ivars where the local variable was mutated before assignment (formula_installer.rb)

Verified with brew typecheck and brew style --fix --changed.


  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests (excluding integration tests) for your changes? (no behaviour change)
  • Have you successfully run brew lgtm (style, typechecking and tests) with your changes locally?

  • AI was used to generate or assist with generating this PR. Claude Code identified all instances of the pattern and applied the removals; changes were verified by running brew typecheck (which autocorrected one file where T.let is still required).

@dduugg dduugg force-pushed the dug/sorbet-remove-redundant-tlet branch from 563ebcb to 8cec91c Compare April 10, 2026 20:48
@dduugg dduugg marked this pull request as ready for review April 10, 2026 20:49
Copilot AI review requested due to automatic review settings April 10, 2026 20:49
@dduugg dduugg enabled auto-merge April 10, 2026 20:49
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR removes redundant T.let calls in initialize methods where instance variables are assigned directly from Sorbet-sig-typed parameters of the same type, relying on Sorbet’s inference to keep ivar types accurate in typed: strict files.

Changes:

  • Replaced @ivar = T.let(param, <same-type>) with @ivar = param across multiple constructors.
  • Kept T.let where it’s still needed (e.g., nil-initialization / conditional assignment / nontrivial assignment patterns), and only simplified the straightforward cases.
  • Ran typechecking/style verification per PR description (no behavioral changes intended).

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated no comments.

Show a summary per file
File Description
Library/Homebrew/unpack_strategy.rb Removes redundant T.let for @ref_type/@ref assigned from sig-typed params.
Library/Homebrew/patch.rb Simplifies ivar assignments in patch-related constructors where params are sig-typed.
Library/Homebrew/migrator.rb Removes redundant T.let for @oldname and @formula assigned from typed params.
Library/Homebrew/mcp_server.rb Simplifies @stdin/@stdout/@stderr assignments from sig-typed keyword params.
Library/Homebrew/linkage_cache_store.rb Removes redundant T.let for @keg_path assigned from typed param.
Library/Homebrew/formula.rb Drops redundant T.let for @tap assigned from a nilable Tap param.
Library/Homebrew/download_strategy.rb Simplifies @cached_location and @version assignments from typed params.
Library/Homebrew/context.rb Removes redundant T.let for nilable boolean context flags assigned from typed params.
Library/Homebrew/cask/installer.rb Simplifies @defer_fetch assignment from a T::Boolean param.
Library/Homebrew/cask/exceptions.rb Removes redundant T.let for @errors assigned from typed param.
Library/Homebrew/cask/dsl/container.rb Simplifies nilable @nested/@type assignments from typed keyword params.
Library/Homebrew/cask/dsl/base.rb Removes redundant T.let for @command assigned from typed param.
Library/Homebrew/cask/dsl.rb Removes redundant T.let for @cask assigned from typed param.
Library/Homebrew/cask/artifact/manpage.rb Simplifies @section assignment from typed param.
Library/Homebrew/cask/artifact/generated_completion.rb Removes redundant T.let for several ivars assigned from typed params.
Library/Homebrew/cache_store.rb Simplifies @type and @database assignments from typed params.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

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

Nice, thanks!

@dduugg dduugg added this pull request to the merge queue Apr 11, 2026
Merged via the queue into main with commit 5717096 Apr 11, 2026
42 checks passed
@dduugg dduugg deleted the dug/sorbet-remove-redundant-tlet branch April 11, 2026 07:16
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.

3 participants