diff --git a/lib/ruby_indexer/lib/ruby_indexer/index.rb b/lib/ruby_indexer/lib/ruby_indexer/index.rb index d14f2812b9..aba69d098d 100644 --- a/lib/ruby_indexer/lib/ruby_indexer/index.rb +++ b/lib/ruby_indexer/lib/ruby_indexer/index.rb @@ -617,13 +617,13 @@ def existing_or_new_singleton_class(name) sig do type_parameters(:T).params( path: String, - type: T.nilable(T::Class[T.all(T.type_parameter(:T), Entry)]), - ).returns(T.nilable(T::Array[T.type_parameter(:T)])) + type: T::Class[T.all(T.type_parameter(:T), Entry)], + ).returns(T::Array[T.type_parameter(:T)]) end def entries_for(path, type = nil) type = Entry if type.nil? - @files_to_entries[path]&.grep(type)&.grep_v(RubyIndexer::Entry::SingletonClass) + Array(@files_to_entries[path]).grep(type).grep_v(RubyIndexer::Entry::SingletonClass) end private diff --git a/lib/ruby_indexer/test/index_test.rb b/lib/ruby_indexer/test/index_test.rb index 41b383fc39..3b0925ed98 100644 --- a/lib/ruby_indexer/test/index_test.rb +++ b/lib/ruby_indexer/test/index_test.rb @@ -1839,5 +1839,9 @@ def self.my_singleton_def; end entries = @index.entries_for("/fake/path/foo.rb", RubyIndexer::Entry::Namespace) assert_equal(["Foo", "Bar"], entries.map(&:name)) end + + def test_entries_for_returns__nil_if_no_matches + assert_empty(@index.entries_for("non_existing_file.rb")) + end end end