Fixed looping when `valuetype` creates self-reference in APIs (ref #297).