1d61d75225
The most interesting part happens in SimpleType.refine, other types either don't implement refinement at all (they return just 'this', mainly it's some special types, like ErrorType and such) or implement it trivially via recursion (those are "composite" types) SimpleType.refine captures so-called refinement factory, which is essentially an injected callback which tells how to reconstruct the type with new (refined) memberScope. We have to inject callback because we express quite different types with SimpleTypeImpl, and some of them need different refinement logic. Another possible implementation approach (more invasive one) would be to extract those types in separate subtypes of KotlinType and implement 'refine' via overrides. The most meaningful callbacks are injected from 'AbstractClassDescriptor.defaultType' and from 'KotlinTypeFactory'.