createInheritanceTypeSubstitutor¶
context(session: KaSession)
fun createInheritanceTypeSubstitutor(subClass: KaClassSymbol, superClass: KaClassSymbol): KaSubstitutor?
Creates a KaSubstitutor based on the inheritance relationship between subClass and superClass. subClass must inherit from superClass and there may not be any error types in the inheritance path. Otherwise, null is returned.
The semantics of the resulting KaSubstitutor are as follows: When applied to a member of superClass, such as a function, its type parameters are substituted in such a way that the resulting member can be used with an instance of subClass.
In other words, the substitutor is a composition of inheritance-based substitutions incorporating the whole inheritance chain.
Example¶
-
createInheritanceTypeSubstitutor(A, B)returnsKaSubstitutor { T -> String } -
createInheritanceTypeSubstitutor(B, C)returnsKaSubstitutor { X -> T, Y -> Int } -
createInheritanceTypeSubstitutor(A, C)returnsKaSubstitutor { X -> T, Y -> Int } and then KaSubstitutor { T -> String }