Skip to content

Conversation

@cho-m
Copy link
Member

@cho-m cho-m commented Dec 21, 2025

  • 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 for your changes? Here's an example.
  • Have you successfully run brew lgtm (style, typechecking and tests) with your changes locally?

This allows Sorbet to track the types rather than needing an extra type assertion.

T.cast is not statically checked (like T.must) so usually better to avoid wherever possible - https://sorbet.org/docs/type-assertions#static-vs-runtime-checking

Copilot AI review requested due to automatic review settings December 21, 2025 18:16
Copy link
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 refactors type assertions in the download/fetch code to use Sorbet's flow-sensitivity instead of explicit T.cast calls. By combining the check_attestation condition with an is_a?(Bottle) type guard, Sorbet can automatically narrow the type without requiring manual type assertions.

Key changes:

  • Replaced T.cast(downloadable_object, Bottle) with runtime type checking using is_a?(Bottle)
  • Combined the attestation check condition with the type guard for cleaner code
  • Removed intermediate bottle variable assignments, passing downloadable_object or downloadable directly

Reviewed changes

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

File Description
Library/Homebrew/formula_installer.rb Refactored attestation check to use flow-sensitive type narrowing instead of T.cast
Library/Homebrew/download_queue.rb Refactored attestation check in download queue to use flow-sensitive type narrowing instead of T.cast

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

Copy link
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.

Oh nice, TIL, thanks @cho-m!

@MikeMcQuaid MikeMcQuaid added this pull request to the merge queue Dec 22, 2025
Merged via the queue into main with commit 938321d Dec 22, 2025
43 checks passed
@MikeMcQuaid MikeMcQuaid deleted the replace-t.cast-bottle branch December 22, 2025 10:09
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