Skip to content

Commit 0d4664b

Browse files
authored
Merge pull request #2638 from Shopify/at-bump-spoom
Bump spoom and set the overload strategy to `translate_last`
2 parents 4a0d1c9 + 1e57691 commit 0d4664b

5 files changed

Lines changed: 118 additions & 28 deletions

File tree

Gemfile.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ PATH
2323
require-hooks (>= 0.2.2)
2424
rubydex (>= 0.1.0.beta10)
2525
sorbet-static-and-runtime (>= 0.6.12698)
26-
spoom (>= 1.7.14)
26+
spoom (>= 1.7.16)
2727
thor (>= 1.2.0)
2828
tsort
2929

@@ -379,7 +379,7 @@ GEM
379379
sorbet-static-and-runtime (0.6.13249)
380380
sorbet (= 0.6.13249)
381381
sorbet-runtime (= 0.6.13249)
382-
spoom (1.7.15)
382+
spoom (1.7.16)
383383
erubi (>= 1.10.0)
384384
prism (>= 0.28.0)
385385
rbi (>= 0.3.3)
@@ -613,7 +613,7 @@ CHECKSUMS
613613
sorbet-static (0.6.13249-universal-darwin) sha256=ab4c79baf38bd307630bc49914667e35f50066966054a4a60dd124011aa42045
614614
sorbet-static (0.6.13249-x86_64-linux) sha256=7b70fb9e7288fb4651d6c8b33faeaad8297edd1c87054b8e6b8f374ae042a577
615615
sorbet-static-and-runtime (0.6.13249) sha256=873c1a29a82411625001e0159e0835679d90d348b1cbb07451ba144b683fff84
616-
spoom (1.7.15) sha256=39698a3bf7841841ae83c6145d5e008290ddb9433e84d9025e017b915bd36a83
616+
spoom (1.7.16) sha256=b6033d1aaede800ef37505474d260d57a02fa63364b4725ea40b6f606e932d59
617617
sprockets (4.2.2) sha256=761e5a49f1c288704763f73139763564c845a8f856d52fba013458f8af1b59b1
618618
sqlite3 (2.9.0-aarch64-linux-gnu) sha256=cfe1e0216f46d7483839719bf827129151e6c680317b99d7b8fc1597a3e13473
619619
sqlite3 (2.9.0-aarch64-linux-musl) sha256=56a35cb2d70779afc2ac191baf2c2148242285ecfed72f9b021218c5c4917913

lib/tapioca/rbs/rewriter.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ def load_iseq(path)
101101

102102
# For performance reasons, we only rewrite files that use Sorbet.
103103
if source =~ /^\s*#\s*typed: (ignore|false|true|strict|strong|__STDLIB_INTERNAL)/
104-
Spoom::Sorbet::Translate.rbs_comments_to_sorbet_sigs(source, file: path)
104+
# Sorbet runtime only supports one signature per method, so keep the last overload.
105+
Spoom::Sorbet::Translate.rbs_comments_to_sorbet_sigs(source, file: path, overloads_strategy: :translate_last)
105106
end
106107
rescue Spoom::Sorbet::Translate::Error
107108
# If we can't translate the RBS comments back into Sorbet's signatures, we just skip the file.
Lines changed: 57 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/tapioca/cli/dsl_spec.rb

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,61 @@ def title; end
739739
assert_success_status(result)
740740
end
741741

742+
it "uses the last overload when rewriting RBS comments" do
743+
@project.write!("lib/post.rb", <<~RB)
744+
# typed: strict
745+
746+
class Post
747+
#: (String value) -> String
748+
#: (Integer value) -> Integer
749+
def find(value)
750+
value
751+
end
752+
end
753+
RB
754+
755+
@project.write!("lib/compilers/rbs_comment_compiler.rb", <<~RB)
756+
require "post"
757+
758+
class RbsCommentCompiler < Tapioca::Dsl::Compiler
759+
extend T::Sig
760+
extend T::Generic
761+
762+
ConstantType = type_member { { fixed: T.class_of(::Post) } }
763+
764+
sig { override.void }
765+
def decorate
766+
root.create_path(constant) do |klass|
767+
create_method_from_def(klass, constant.instance_method(:find))
768+
end
769+
end
770+
771+
sig { override.returns(T::Enumerable[T::Module[T.anything]]) }
772+
def self.gather_constants
773+
[::Post]
774+
end
775+
end
776+
RB
777+
778+
result = @project.tapioca("dsl Post --only RbsCommentCompiler")
779+
780+
assert_empty_stderr(result)
781+
assert_project_file_equal("sorbet/rbi/dsl/post.rbi", <<~RBI)
782+
# typed: true
783+
784+
# DO NOT EDIT MANUALLY
785+
# This is an autogenerated file for dynamic methods in `Post`.
786+
# Please instead update this file by running `bin/tapioca dsl Post`.
787+
788+
789+
class Post
790+
sig { params(value: ::Integer).returns(::Integer) }
791+
def find(value); end
792+
end
793+
RBI
794+
assert_success_status(result)
795+
end
796+
742797
it "raises when the host calls Bootsnap.setup under TAPIOCA_RBS_CACHE=1" do
743798
@project.write!("lib/post.rb", <<~RB)
744799
require "bootsnap"

tapioca.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Gem::Specification.new do |spec|
3535
# Tapioca requires a specific minimum versions of RBI and Spoom
3636
# to ensure that the RBS comments are translated correctly.
3737
spec.add_dependency("rbi", ">= 0.3.7")
38-
spec.add_dependency("spoom", ">= 1.7.14")
38+
spec.add_dependency("spoom", ">= 1.7.16")
3939
# We need this to be ported to the RBS 4.0 branch before we can remove this dependency:
4040
# https://github.com/ruby/rbs/pull/2601
4141
spec.add_dependency("tsort") # Until rbs supports Ruby 4.0 with tsort extracted to bundled gems

0 commit comments

Comments
 (0)