From e63111a7b5c017def7a6c5d3e23b81b9447bd5ba Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Fri, 3 Mar 2023 18:41:19 -0800 Subject: [PATCH 1/2] resolve type error in --env --- Library/Homebrew/cmd/--env.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/cmd/--env.rb b/Library/Homebrew/cmd/--env.rb index a442e6ad4b..04c61bc19f 100644 --- a/Library/Homebrew/cmd/--env.rb +++ b/Library/Homebrew/cmd/--env.rb @@ -49,7 +49,7 @@ module Homebrew end if shell.nil? - BuildEnvironment.dump ENV + BuildEnvironment.dump ENV.to_h else BuildEnvironment.keys(ENV.to_h).each do |key| puts Utils::Shell.export_value(key, ENV.fetch(key), shell) From b7d295341235fc3f47c7bc2153b14c91bcb579c3 Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Fri, 3 Mar 2023 18:54:49 -0800 Subject: [PATCH 2/2] enable typing in --env --- Library/Homebrew/cli/parser.rb | 4 +++- Library/Homebrew/cmd/--env.rb | 2 +- Library/Homebrew/extend/ENV.rbi | 1 + Library/Homebrew/postinstall.rb | 2 +- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/cli/parser.rb b/Library/Homebrew/cli/parser.rb index 568ab62d06..536a100a28 100644 --- a/Library/Homebrew/cli/parser.rb +++ b/Library/Homebrew/cli/parser.rb @@ -296,7 +296,9 @@ module Homebrew [remaining, non_options] end - sig { params(argv: T::Array[String], ignore_invalid_options: T::Boolean).returns(Args) } + # @return [Args] The actual return type is `Args`, but since `Args` uses `method_missing` to handle options, the + # `sig` annotates this as returning `T.untyped` to avoid spurious type errors. + sig { params(argv: T::Array[String], ignore_invalid_options: T::Boolean).returns(T.untyped) } def parse(argv = ARGV.freeze, ignore_invalid_options: false) raise "Arguments were already parsed!" if @args_parsed diff --git a/Library/Homebrew/cmd/--env.rb b/Library/Homebrew/cmd/--env.rb index 04c61bc19f..f9814ccd94 100644 --- a/Library/Homebrew/cmd/--env.rb +++ b/Library/Homebrew/cmd/--env.rb @@ -1,4 +1,4 @@ -# typed: false +# typed: strict # frozen_string_literal: true require "extend/ENV" diff --git a/Library/Homebrew/extend/ENV.rbi b/Library/Homebrew/extend/ENV.rbi index f1fa0b4dcf..0c7c926da8 100644 --- a/Library/Homebrew/extend/ENV.rbi +++ b/Library/Homebrew/extend/ENV.rbi @@ -36,6 +36,7 @@ end module EnvActivation include EnvMethods + include Superenv end class Sorbet diff --git a/Library/Homebrew/postinstall.rb b/Library/Homebrew/postinstall.rb index f546df2727..ee5f1e798c 100644 --- a/Library/Homebrew/postinstall.rb +++ b/Library/Homebrew/postinstall.rb @@ -19,7 +19,7 @@ begin trap("INT", old_trap) - formula = T.must(args.named.to_resolved_formulae.first) + formula = args.named.to_resolved_formulae.first formula.extend(Debrew::Formula) if args.debug? formula.run_post_install rescue Exception => e # rubocop:disable Lint/RescueException