Detect circular references and throw a LogicException