Only generate poly contracts for functions

Closes PR 13815