ReporterHub#select_formula_or_cask: fix type - #23330
Merged
Merged
Conversation
`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.
Contributor
There was a problem hiding this comment.
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 andselect_formula_or_caskreturn type to reflect rename tuples, removing an incorrect internal cast. - Add
T.castat call sites that are known to operate onT::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.
MikeMcQuaid
approved these changes
Jul 28, 2026
MikeMcQuaid
left a comment
Member
There was a problem hiding this comment.
Thanks, looks good when 🟢. Some tests to exercise this (AI generated is fine) would be nice.
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.
brewcommands to reproduce the bug?brew lgtm(style, typechecking and tests) locally?ReporterHub#select_formula_or_caskhas a method signature suggesting that it only returns an array of strings and it usesT.castinternally but the array values from@hashcan be a string or[String, String]array. The latter occurs when the:Rkey 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 theDescriptionCacheStore#update_from_report!method and this produces a type error when theHOMEBREW_SORBET_RECURSIVE=1environment variable is set and a renamed package is updated, as the aforementionedT.cast(..., T::Array[String])inselect_formula_or_caskis incorrect in this scenario.This addresses the issue by updating the
@hashtype, aligning the return type ofselect_formula_or_cask, and removing the cast inside the method. This predictably causesbrew typecheckto surface type errors in areas whereselect_formula_or_caskis 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 addingT.castcalls to the related areas to define the type.