Skip to content

Commit 9a4240a

Browse files
committed
Always use @without_runtime for method_added
1 parent 29922d5 commit 9a4240a

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

lib/spoom/sorbet/translate/rbs_comments_to_sorbet_sigs.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,12 @@ def rewrite_def(def_node, comments)
139139

140140
apply_member_annotations(comments.method_annotations, sig)
141141

142+
# Sorbet runtime doesn't support `sig` on `method_added` or
143+
# `singleton_method_added`, so we always use `without_runtime` for them.
144+
if def_node.name == :method_added || def_node.name == :singleton_method_added
145+
sig.without_runtime = true
146+
end
147+
142148
@rewriter << Source::Replace.new(
143149
signature.location.start_offset,
144150
signature.location.end_offset,

test/spoom/sorbet/translate/rbs_comments_to_sorbet_sigs_test.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,36 @@ def foo; end
124124
RB
125125
end
126126

127+
def test_translate_to_rbi_method_added_is_always_without_runtime
128+
contents = <<~RB
129+
class A
130+
class << self
131+
# @override
132+
#: (Symbol) -> void
133+
def method_added(m); end
134+
135+
# @override
136+
#: (Symbol) -> void
137+
def singleton_method_added(m); end
138+
end
139+
end
140+
RB
141+
142+
assert_equal(<<~RB, rbs_comments_to_sorbet_sigs(contents))
143+
class A
144+
class << self
145+
# @override
146+
T::Sig::WithoutRuntime.sig { override.params(m: Symbol).void }
147+
def method_added(m); end
148+
149+
# @override
150+
T::Sig::WithoutRuntime.sig { override.params(m: Symbol).void }
151+
def singleton_method_added(m); end
152+
end
153+
end
154+
RB
155+
end
156+
127157
def test_translate_to_rbi_singleton_method_sigs
128158
contents = <<~RB
129159
class A

0 commit comments

Comments
 (0)