diff --git a/lib/ruby_indexer/lib/ruby_indexer/index.rb b/lib/ruby_indexer/lib/ruby_indexer/index.rb index 89fd510d2..da8a0448b 100644 --- a/lib/ruby_indexer/lib/ruby_indexer/index.rb +++ b/lib/ruby_indexer/lib/ruby_indexer/index.rb @@ -619,13 +619,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 aa027c12e..54d50be96 100644 --- a/lib/ruby_indexer/test/index_test.rb +++ b/lib/ruby_indexer/test/index_test.rb @@ -1859,5 +1859,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