Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/spoom/sorbet/translate/rbs_comments_to_sorbet_sigs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ def rewrite_def(def_node, comments)

apply_member_annotations(comments.method_annotations, sig)

# Sorbet runtime doesn't support `sig` on `method_added` or
# `singleton_method_added`, so we always use `without_runtime` for them.
if def_node.name == :method_added || def_node.name == :singleton_method_added
sig.without_runtime = true
end

@rewriter << Source::Replace.new(
signature.location.start_offset,
signature.location.end_offset,
Expand Down
30 changes: 30 additions & 0 deletions test/spoom/sorbet/translate/rbs_comments_to_sorbet_sigs_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,36 @@ def foo; end
RB
end

def test_translate_to_rbi_method_added_is_always_without_runtime
contents = <<~RB
class A
class << self
# @override
#: (Symbol) -> void
def method_added(m); end

# @override
#: (Symbol) -> void
def singleton_method_added(m); end
end
end
RB

assert_equal(<<~RB, rbs_comments_to_sorbet_sigs(contents))
class A
class << self
# @override
T::Sig::WithoutRuntime.sig { override.params(m: Symbol).void }
def method_added(m); end

# @override
T::Sig::WithoutRuntime.sig { override.params(m: Symbol).void }
def singleton_method_added(m); end
end
end
RB
end

def test_translate_to_rbi_singleton_method_sigs
contents = <<~RB
class A
Expand Down