Handle interactions between recursive aliases and recursive instances (#13328)
This is a follow-up for #13297
The fix for infinite recursion is kind of simple, but it is hard to make inference infer something useful. Currently we handle all most common cases, but it is quite fragile (I however have few tricks left if people will complain about inference).