Fix subtyping of invariant data structures.

Closes PR13521.