Skip to content

Fix DSL#env override covariance error#22023

Merged
MikeMcQuaid merged 2 commits intomainfrom
fix-dsl-env-override-covariance
Apr 15, 2026
Merged

Fix DSL#env override covariance error#22023
MikeMcQuaid merged 2 commits intomainfrom
fix-dsl-env-override-covariance

Conversation

@MikeMcQuaid
Copy link
Copy Markdown
Member

  • typed: strict on build_environment.rb tightened DSL#env to returns(BuildEnvironment) but the Requirement override legitimately returns nil
  • Mark DSL#env as overridable with nilable return
  • Replace T.must with explicit ArgumentError guard
  • Add missing override. to Requirement.env sig

Fixes #22022


  • 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? Performance claims (e.g. "this is faster") must include Hyperfine benchmarks.
  • Have you written new tests (excluding integration tests) for your changes? Here's an example.
  • 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. Please specify below how you used AI to help you, and what steps you have taken to manually verify the changes. Non-maintainers may only have one AI-assisted/generated PR open at a time.

Worked with Claude Code with manual review and testing.


- `typed: strict` on `build_environment.rb` tightened
  `DSL#env` to `returns(BuildEnvironment)` but the
  `Requirement` override legitimately returns `nil`
- Mark `DSL#env` as `overridable` with nilable return
- Replace `T.must` with explicit `ArgumentError` guard
- Add missing `override.` to `Requirement.env` sig
Copilot AI review requested due to automatic review settings April 15, 2026 14:08
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

Resolves a Sorbet covariance/typechecking error around BuildEnvironment::DSL#env so that Requirement.env can legitimately return nil when used in its block form.

Changes:

  • Make BuildEnvironment::DSL#env overridable and widen its return type to T.nilable(BuildEnvironment) to support nil-returning overrides.
  • Replace T.must(@env) with an explicit ArgumentError guard when @env is not initialized.
  • Mark Requirement.env’s signature as an explicit override.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
Library/Homebrew/build_environment.rb Widen DSL#env return type for override compatibility and add explicit guard when @env is unset.
Library/Homebrew/requirement.rb Mark env sig as override to match the intended Sorbet override relationship.

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

Comment thread Library/Homebrew/build_environment.rb
@MikeMcQuaid MikeMcQuaid enabled auto-merge April 15, 2026 15:22
Comment thread Library/Homebrew/build_environment.rb
@MikeMcQuaid MikeMcQuaid added this pull request to the merge queue Apr 15, 2026
Merged via the queue into main with commit 1ff09fb Apr 15, 2026
36 checks passed
@MikeMcQuaid MikeMcQuaid deleted the fix-dsl-env-override-covariance branch April 15, 2026 15:49
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.

brew cleanup (and brew doctor) fail with Sorbet covariance error: incompatible return type override of env in requirement.rb

4 participants