From 4e0a8df574629309dc3d1e018d0621327ca8c644 Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Thu, 22 Oct 2026 14:14:08 -0700 Subject: [PATCH] Keep visibility from bare sections in exported gem RBIs The RBI parser records a bare `private` or `protected` as a standalone node and leaves the following methods public. The merge in `exported_rbi_tree` drops those standalone nodes, so methods declared only in an exported RBI were generated as public. Flatten each exported file's visibilities onto its methods before merging. --- lib/tapioca/gemfile.rb | 2 ++ spec/tapioca/cli/gem_spec.rb | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/lib/tapioca/gemfile.rb b/lib/tapioca/gemfile.rb index 5cdc92a7b..62da4a6ac 100644 --- a/lib/tapioca/gemfile.rb +++ b/lib/tapioca/gemfile.rb @@ -206,6 +206,8 @@ def exported_rbi_tree exported_rbi_files.each do |file| rbi = RBI::Parser.parse_file(file) + # Merging drops standalone `private`/`protected` nodes, so move their visibility onto each method first + rbi.flatten_visibilities! rewriter.merge(rbi) end diff --git a/spec/tapioca/cli/gem_spec.rb b/spec/tapioca/cli/gem_spec.rb index 70199bb38..cd44109e5 100644 --- a/spec/tapioca/cli/gem_spec.rb +++ b/spec/tapioca/cli/gem_spec.rb @@ -334,6 +334,10 @@ def self.foo(a = T.unsafe(nil), b: T.unsafe(nil), **opts); end write!("rbi/foo/bar.rbi", <<~RBI) module Foo def foo; end + + private + + def baz; end end RBI @@ -362,6 +366,10 @@ def bar; end module Foo def foo; end + private + + def baz; end + class << self sig { params(a: String, b: Integer, opts: T.untyped).void } def foo(a = T.unsafe(nil), b: T.unsafe(nil), **opts); end