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

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