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
7 changes: 6 additions & 1 deletion lib/tapioca/gem/listeners/sorbet_signatures.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ def on_method(event)
signature = event.signature
return unless signature

event.node.sigs << compile_signature(signature, event.parameters)
sig = compile_signature(signature, event.parameters)
# `initialize` must always return void. When a sig uses `.void.checked(:tests)`,
# Sorbet introspects the return type as `T.anything` outside of test mode, so we
# correct it here.
sig.return_type = "void" if event.node.name == "initialize"
event.node.sigs << sig
end

#: (untyped signature, Array[[Symbol, String]] parameters) -> RBI::Sig
Expand Down
22 changes: 22 additions & 0 deletions spec/tapioca/gem/pipeline_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2225,6 +2225,28 @@ def initialize; end
assert_equal(output, compile)
end

it "compiles initialize with void sig using checked(:tests)" do
add_ruby_file("bar.rb", <<~RUBY)
class Bar
extend T::Sig

sig { params(x: Integer).void.checked(:tests) }
def initialize(x)
@x = x
end
end
RUBY

output = template(<<~RBI)
class Bar
sig { params(x: ::Integer).void }
def initialize(x); end
end
RBI

assert_equal(output, compile)
end

it "understands redefined attr_accessor" do
add_ruby_file("toto.rb", <<~RUBY)
class Toto
Expand Down
Loading