[NI] Use alternative to intersection type in public declarations
The new inference uses inferred intersection types normally, unlike the old inference.
However, intersection types in public declarations are approximated to supertype, which
potentially may give a less presice type, then it would be with the OI.
For non-related T1, T2 the NI approximates {T1 & T2} to Any in public declarations,
and if the OI was inferring T1 instead of the intersection type, it may lead to
less precise declaration type and related errors.
The solution is to remember an alternative for an intersection type when present.
Before approximation the alternative replaces the intersection type.
^KT-36249 Fixed
This commit is contained in:
@@ -113,15 +113,14 @@ fun getErasedReceiverType(receiverParameterDescriptor: ReceiverParameterDescript
|
||||
fakeTypeArguments.add(TypeProjectionImpl(typeProjection.projectionKind, DONT_CARE))
|
||||
}
|
||||
|
||||
val receiverTypeConstructor = if (receiverType.constructor is IntersectionTypeConstructor) {
|
||||
val superTypesWithFakeArguments = receiverType.constructor.supertypes.map { supertype ->
|
||||
val oldReceiverTypeConstructor = receiverType.constructor
|
||||
val receiverTypeConstructor = if (oldReceiverTypeConstructor is IntersectionTypeConstructor) {
|
||||
oldReceiverTypeConstructor.transformComponents { supertype ->
|
||||
val fakeArguments = supertype.arguments.map { TypeProjectionImpl(it.projectionKind, DONT_CARE) }
|
||||
supertype.replace(fakeArguments)
|
||||
}
|
||||
|
||||
IntersectionTypeConstructor(superTypesWithFakeArguments)
|
||||
} ?: oldReceiverTypeConstructor
|
||||
} else {
|
||||
receiverType.constructor
|
||||
oldReceiverTypeConstructor
|
||||
}
|
||||
|
||||
return KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(
|
||||
|
||||
-2
@@ -34,8 +34,6 @@ import org.jetbrains.kotlin.resolve.scopes.receivers.ImplicitReceiver
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
import org.jetbrains.kotlin.types.checker.TypeIntersector
|
||||
import org.jetbrains.kotlin.types.checker.intersectTypes
|
||||
import org.jetbrains.kotlin.types.checker.intersectWrappedTypes
|
||||
import org.jetbrains.kotlin.types.typeUtil.expandIntersectionTypeIfNecessary
|
||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||
|
||||
Reference in New Issue
Block a user