Make type->contract correctly respect variance.

Closes PR 13662.
Closes PR 13663.