From 2acbb920c5b3af6a4d0d8ea1ee24b405328b1277 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Efe=20G=C3=B6kdemir?= Date: Wed, 28 Oct 2026 17:19:51 +0300 Subject: [PATCH 1/2] Skip constants nested under payload aliases --- lib/tapioca/gem/pipeline.rb | 13 ++++++++++++- spec/tapioca/gem/pipeline_spec.rb | 14 ++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/tapioca/gem/pipeline.rb b/lib/tapioca/gem/pipeline.rb index ebb35faee..c2906ed1c 100644 --- a/lib/tapioca/gem/pipeline.rb +++ b/lib/tapioca/gem/pipeline.rb @@ -480,9 +480,20 @@ def add_to_alias_namespace(name) #: (String name) -> bool def alias_namespaced?(name) - @alias_namespace.any? do |namespace| + return true if @alias_namespace.any? do |namespace| name.start_with?(namespace) end + + parts = name.split("::") + parts.pop + + parts.each_index.any? do |index| + namespace = T.must(parts[0..index]).join("::") + next false unless symbol_in_payload?(namespace) + + constant = constantize(namespace) + Runtime::Reflection.constant_defined?(constant) && Module === constant && name_of(constant) != namespace + end end #: (String name) -> void diff --git a/spec/tapioca/gem/pipeline_spec.rb b/spec/tapioca/gem/pipeline_spec.rb index 43a52ed94..81ec51421 100644 --- a/spec/tapioca/gem/pipeline_spec.rb +++ b/spec/tapioca/gem/pipeline_spec.rb @@ -689,6 +689,20 @@ module Foo::Bar; end RBI end + it "does not generate constants nested in a payload alias" do + mock_gem("yaml") do + add_ruby_file("lib/yaml.rb", <<~RB) + require "yaml" + + module YAML + LOADER_VERSION = "0.4.0" + end + RB + end + + assert_equal("", compile("yaml")) + end + it "must do mixin attribution properly" do # This is pattern is taken from the private `typed_parameters` gem. add_ruby_file("lib/typed_parameters.rb", <<~RUBY) From 4c41196f581512d49f42308aab04b04b7801cc37 Mon Sep 17 00:00:00 2001 From: Efe Date: Sun, 15 Nov 2026 08:34:22 +0300 Subject: [PATCH 2/2] Simplify payload alias namespace prefixes Use first(index + 1) to preserve the inclusive prefix length while avoiding the redundant T.must around an array slice. --- lib/tapioca/gem/pipeline.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tapioca/gem/pipeline.rb b/lib/tapioca/gem/pipeline.rb index c2906ed1c..99f6da8a7 100644 --- a/lib/tapioca/gem/pipeline.rb +++ b/lib/tapioca/gem/pipeline.rb @@ -488,7 +488,7 @@ def alias_namespaced?(name) parts.pop parts.each_index.any? do |index| - namespace = T.must(parts[0..index]).join("::") + namespace = parts.first(index + 1).join("::") next false unless symbol_in_payload?(namespace) constant = constantize(namespace)