fix assertion: detect cycles in types