Fix require/untyped-contract to generate better names in contracts.

Related to PR 13716.