Catch circular inheritance by detecting recursion blowout.

Close #1255.