Check for cyclic solutions in unification

Fixes #602