Make dependencies.rb add a name to NameError
Merge pull request #15909 from yuki24/fix-name-error-name-bug-4-1

Backport of #15764 and #15902 to 4-1-stable