lib/tapioca/gem/pipeline.rb in tapioca-0.10.5 vs lib/tapioca/gem/pipeline.rb in tapioca-0.11.0

- old
+ new

@@ -104,10 +104,22 @@ return false unless symbol_name @payload_symbols.include?(symbol_name) end + sig { params(name: T.any(String, Symbol)).returns(T::Boolean) } + def constant_in_gem?(name) + return true unless Object.respond_to?(:const_source_location) + + source_location, _ = Object.const_source_location(name) + return true unless source_location + # If the source location of the constant is "(eval)", all bets are off. + return true if source_location == "(eval)" + + gem.contains_path?(source_location) + end + sig { params(method: UnboundMethod).returns(T::Boolean) } def method_in_gem?(method) source_location = method.source_location&.first return false if source_location.nil? @@ -214,10 +226,11 @@ return if seen?(name) mark_seen(name) return if symbol_in_payload?(name) + return unless constant_in_gem?(name) target = name_of(constant) # If target has no name, let's make it an anonymous class or module with `Class.new` or `Module.new` target = "#{constant.class}.new" unless target @@ -235,9 +248,10 @@ return if seen?(name) mark_seen(name) return if symbol_in_payload?(name) + return unless constant_in_gem?(name) klass = class_of(value) klass_name = if klass == ObjectSpace::WeakMap sorbet_supports?(:non_generic_weak_map) ? "ObjectSpace::WeakMap" : "ObjectSpace::WeakMap[T.untyped]"