Terminate typechecking on cyclic lists.

Closes PR 13687.