Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix type errors when HOMEBREW_SORBET_RUNTIME=1 #15710

Merged
merged 2 commits into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions Library/Homebrew/cask/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,12 @@ def explicit_s
end

sig { params(options: T.untyped).returns(String) }
def to_json(**options)
def to_json(*options)
{
default: default,
env: env,
explicit: explicit,
}.to_json(**options)
}.to_json(*options)
end
end
end
1 change: 1 addition & 0 deletions Library/Homebrew/dev-cmd/generate-cask-api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

require "cli/parser"
require "cask/cask"
require "formula"
Copy link
Sponsor Member Author

Choose a reason for hiding this comment

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

resolves

$ brew generate-cask-api
Error: Error while generating data for cask '0-ad'.
Error: Cask '0-ad' is unreadable: uninitialized constant Formula

(This treats the symptom, but it might make more sense to add require "formula" in livecheck.rb or otherwise resolve this issue there.)

Copy link
Member

Choose a reason for hiding this comment

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

Where does this come from? In theory casks and formulae should be separate.

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

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

It comes in via requiring livecheck transitively: https://github.com/Homebrew/brew/blob/4.0.29/Library/Homebrew/livecheck.rb#L22

We only see this with sorbet enabled, as otherwise the block is not evaluated. The Formula reference there is needed bc otherwise:

$ brew typecheck
formula.rb:2822: Expected T.any(Cask::Cask, Resource) but found T.class_of(Formula) for argument package_or_resource https://srb.help/7002
    2822 |        @livecheck = Livecheck.new(self)
                                             ^^^^
  Expected T.any(Cask::Cask, Resource) for argument package_or_resource of method Livecheck#initialize:
    livecheck.rb:22:
    22 |  sig { params(package_or_resource: T.any(Cask::Cask, Resource)).void }

(I'm not positive this is answering your question though)

Copy link
Member

@Bo98 Bo98 Jul 18, 2023

Choose a reason for hiding this comment

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

Oh right, the type signatures.

This is probably good enough for now (assuming brew livecheck and brew audit --cask on a cask with a livecheck block works), but I guess in the longer term we should have a baseclass for any sort of package/resource rather than this T.any stuff. In theory the existing Downloadable will probably work with some adjustments. Might be the next big refactor work I can look into.


module Homebrew
module_function
Expand Down
6 changes: 3 additions & 3 deletions Library/Homebrew/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -711,9 +711,9 @@ def to_str
T.must(version).to_str
end

sig { params(options: Hash).returns(String) }
def to_json(**options)
version.to_json(**options)
sig { params(options: T.untyped).returns(String) }
def to_json(*options)
Copy link
Sponsor Member Author

Choose a reason for hiding this comment

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

version.to_json(*options)
end

sig { params(method: T.any(Symbol, String), include_all: T::Boolean).returns(T::Boolean) }
Expand Down