Skip to content

ReporterHub#select_formula_or_cask: fix type - #23330

Merged
MikeMcQuaid merged 1 commit into
mainfrom
select_formula_or_cask-fix-type
Jul 31, 2026
Merged

ReporterHub#select_formula_or_cask: fix type#23330
MikeMcQuaid merged 1 commit into
mainfrom
select_formula_or_cask-fix-type

Conversation

@samford

@samford samford commented Jul 27, 2026

Copy link
Copy Markdown
Member

  • Have you followed our Contributing guidelines?
  • Have you checked for other open Pull Requests for the same change?
  • Have you explained what your changes do? Performance claims (e.g. "this is faster") must include Hyperfine benchmarks.
  • Have you explained why you'd like these changes included, not just what they do?
  • For bug fixes, have you given step-by-step brew commands to reproduce the bug?
  • Have you written new tests (excluding integration tests)? Here's an example.
  • Have you successfully run brew lgtm (style, typechecking and tests) locally?

  • AI was used to generate or assist with generating this PR.

ReporterHub#select_formula_or_cask has a method signature suggesting that it only returns an array of strings and it uses T.cast internally but the array values from @hash can be a string or [String, String] array. The latter occurs when the :R key is used to represent a package rename, where the first string in the array is the previous name and the second string is the new/current name. select_formula_or_cask(:R) is used in the
DescriptionCacheStore#update_from_report! method and this produces a type error when the HOMEBREW_SORBET_RECURSIVE=1 environment variable is set and a renamed package is updated, as the aforementioned T.cast(..., T::Array[String]) in select_formula_or_cask is incorrect in this scenario.

This addresses the issue by updating the @hash type, aligning the return type of select_formula_or_cask, and removing the cast inside the method. This predictably causes brew typecheck to surface type errors in areas where select_formula_or_cask is called and the value isn't cast, as Sorbet doesn't know whether the value is an array of strings or [String, String] based on the argument. I've accounted for this by adding T.cast calls to the related areas to define the type.

`ReporterHub#select_formula_or_cask` has a method signature suggesting
that it only returns an array of strings and it uses `T.cast`
internally but the array values from `@hash` can be a string or
`[String, String]` array. The latter occurs when the `:R` key is used
to represent a package rename, where the first string in the array is
the previous name and the second string is the new/current name.
`select_formula_or_cask(:R)` is used in the
`DescriptionCacheStore#update_from_report!` method and this produces a
type error when the `HOMEBREW_SORBET_RECURSIVE=1` environment variable
is set and a renamed package is updated, as the aforementioned
`T.cast(..., T::Array[String])` in `select_formula_or_cask` is
incorrect in this scenario.

This addresses the issue by updating the `@hash` type, aligning the
return type of `select_formula_or_cask`, and removing the cast inside
the method. This predictably causes `brew typecheck` to surface type
errors in areas where `select_formula_or_cask` is called and the value
isn't cast, as Sorbet doesn't know whether the value is an array of
strings or `[String, String]` based on the argument. I've accounted
for this by adding `T.cast` calls to the related areas to define the
type.
Copilot AI review requested due to automatic review settings July 27, 2026 22:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 fixes Sorbet typing around ReporterHub#select_formula_or_cask, whose underlying report data can include either plain String entries or rename tuples ([String, String]), and updates downstream call sites to make the intended element types explicit.

Changes:

  • Adjust ReporterHub’s internal report hash typing and select_formula_or_cask return type to reflect rename tuples, removing an incorrect internal cast.
  • Add T.cast at call sites that are known to operate on T::Array[String] (e.g., cache store updates and report dumping).
  • Tighten rename typing to tuples (T::Array[[String, String]]) where rename data is consumed.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
Library/Homebrew/description_cache_store/cask_description_cache_store.rb Adds casts for updated select_formula_or_cask typing (but currently still misses :RC rename handling).
Library/Homebrew/description_cache_store.rb Updates formula cache update logic to use tuple renames and casts concatenated results to T::Array[String].
Library/Homebrew/cmd/update_report/reporter_hub.rb Updates @hash and select_formula_or_cask Sorbet types and adds casts in report output paths.

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

Comment thread Library/Homebrew/description_cache_store.rb

@MikeMcQuaid MikeMcQuaid left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, looks good when 🟢. Some tests to exercise this (AI generated is fine) would be nice.

@MikeMcQuaid
MikeMcQuaid added this pull request to the merge queue Jul 31, 2026
Merged via the queue into main with commit 98fdeb3 Jul 31, 2026
44 checks passed
@MikeMcQuaid
MikeMcQuaid deleted the select_formula_or_cask-fix-type branch July 31, 2026 08:15
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