[NI] Fix substitutor for anonymous types with captured type parameters

This commit is contained in:
Mikhail Zarechenskiy
2018-04-17 14:26:52 +03:00
parent b7fa06cca4
commit c216749eb6
3 changed files with 19 additions and 5 deletions
@@ -574,7 +574,7 @@ class DelegatedPropertyResolver(
val resolvedDelegateType = extractResolvedDelegateType(delegateExpression, trace)
return AnonymousTypeSubstitutor.safeSubstitute(resolvedDelegateType.unwrap())
return TypeSubstitutor.create(AnonymousTypeSubstitutor).safeSubstitute(resolvedDelegateType, Variance.INVARIANT).unwrap()
}
private fun extractResolvedDelegateType(delegateExpression: KtExpression, trace: BindingTrace): KotlinType {
@@ -703,11 +703,11 @@ class DelegatedPropertyResolver(
}
}
private object AnonymousTypeSubstitutor : NewTypeSubstitutor {
override fun substituteNotNullTypeWithConstructor(constructor: TypeConstructor): UnwrappedType? {
val declarationDescriptor = constructor.declarationDescriptor
private object AnonymousTypeSubstitutor : TypeConstructorSubstitution() {
override fun get(key: TypeConstructor): TypeProjection? {
val declarationDescriptor = key.declarationDescriptor
if (declarationDescriptor is ClassifierDescriptor && DescriptorUtils.isAnonymousObject(declarationDescriptor)) {
return constructor.supertypes.firstOrNull()?.unwrap()
return key.supertypes.firstOrNull()?.let(::TypeProjectionImpl)
}
return null