Split stub types into stub type for subtyping and for builder inference and use them in the proper way

This commit is contained in:
Victor Petukhov
2021-05-11 17:14:05 +03:00
parent 703a353d2e
commit 5a11450d77
18 changed files with 97 additions and 101 deletions
@@ -45,7 +45,7 @@ class BuilderInferenceSession(
callComponents: KotlinCallComponents,
builtIns: KotlinBuiltIns,
private val topLevelCallContext: BasicCallResolutionContext,
private val stubsForPostponedVariables: Map<NewTypeVariable, StubType>,
private val stubsForPostponedVariables: Map<NewTypeVariable, StubTypeForBuilderInference>,
private val trace: BindingTrace,
private val kotlinToResolvedCallTransformer: KotlinToResolvedCallTransformer,
private val expressionTypingServices: ExpressionTypingServices,
@@ -117,7 +117,7 @@ class BuilderInferenceSession(
private fun KotlinType.containsStubType(): Boolean {
return this.contains {
it is StubType
it is StubTypeForBuilderInference
}
}
@@ -134,8 +134,8 @@ class BuilderInferenceSession(
}
private fun anyReceiverContainStubType(descriptor: CallableDescriptor): Boolean {
return descriptor.dispatchReceiverParameter?.type?.contains { it is StubType } == true ||
descriptor.extensionReceiverParameter?.type?.contains { it is StubType } == true
return descriptor.dispatchReceiverParameter?.type?.contains { it is StubTypeForBuilderInference } == true ||
descriptor.extensionReceiverParameter?.type?.contains { it is StubTypeForBuilderInference } == true
}
private fun isTopLevelBuilderInferenceCall() = findParentBuildInferenceSession() == null
@@ -296,7 +296,7 @@ class CoroutineInferenceSupport(
}
}
private fun KotlinType.containsTypeTemplate() = contains { it is TypeTemplate || it is StubType }
private fun KotlinType.containsTypeTemplate() = contains { it is TypeTemplate || it is StubTypeForBuilderInference }
fun isApplicableCallForBuilderInference(descriptor: CallableDescriptor, languageVersionSettings: LanguageVersionSettings): Boolean {
if (!languageVersionSettings.supportsFeature(LanguageFeature.ExperimentalBuilderInference)) {
@@ -90,7 +90,7 @@ class KotlinResolutionCallbacksImpl(
parameters: List<UnwrappedType>,
expectedReturnType: UnwrappedType?,
annotations: Annotations,
stubsForPostponedVariables: Map<NewTypeVariable, StubType>,
stubsForPostponedVariables: Map<NewTypeVariable, StubTypeForBuilderInference>,
): ReturnArgumentsAnalysisResult {
val psiCallArgument = lambdaArgument.psiCallArgument as PSIFunctionKotlinCallArgument
val outerCallContext = psiCallArgument.outerCallContext
@@ -989,7 +989,7 @@ private fun CallableMemberDescriptor.isNotSimpleCall(): Boolean =
it is NewCapturedType ||
it.constructor is IntegerLiteralTypeConstructor ||
it is DefinitelyNotNullType ||
it is StubType
it is StubTypeForBuilderInference
}
} ?: false)
@@ -415,7 +415,7 @@ class ResolvedAtomCompleter(
val rawExtensionReceiver = callableCandidate.extensionReceiver
if (rawExtensionReceiver != null && rawExtensionReceiver.receiver.receiverValue.type.contains { it is StubType }) {
if (rawExtensionReceiver != null && rawExtensionReceiver.receiver.receiverValue.type.contains { it is StubTypeForBuilderInference }) {
topLevelTrace.reportDiagnosticOnce(Errors.TYPE_INFERENCE_POSTPONED_VARIABLE_IN_RECEIVER_TYPE.on(callableReferenceExpression))
return
}
@@ -286,7 +286,7 @@ public class DataFlowAnalyzer {
@NotNull Ref<Boolean> hasError,
boolean reportErrorForTypeMismatch
) {
if (!noExpectedType(c.expectedType) && TypeUtilsKt.contains(expressionType, (type) -> type instanceof StubType)) {
if (!noExpectedType(c.expectedType) && TypeUtilsKt.contains(expressionType, (type) -> type instanceof StubTypeForBuilderInference)) {
if (c.inferenceSession instanceof BuilderInferenceSession) {
((BuilderInferenceSession) c.inferenceSession).addExpectedTypeConstraint(expression, expressionType, c.expectedType);
}
@@ -114,7 +114,7 @@ class DoubleColonExpressionResolver(
} else {
val result = resolveDoubleColonLHS(expression, c)
if (c.inferenceSession is BuilderInferenceSession && result?.type?.contains { it is StubType } == true) {
if (c.inferenceSession is BuilderInferenceSession && result?.type?.contains { it is StubTypeForBuilderInference } == true) {
c.inferenceSession.addOldCallableReferenceCalls(expression)
}
@@ -548,7 +548,7 @@ class DoubleColonExpressionResolver(
val result = getCallableReferenceType(expression, lhs, resolutionResults, c)
val doesSomeExtensionReceiverContainsStubType =
resolutionResults != null && resolutionResults.resultingCalls.any { resolvedCall ->
resolvedCall.extensionReceiver?.type?.contains { it is StubType } == true
resolvedCall.extensionReceiver?.type?.contains { it is StubTypeForBuilderInference } == true
}
if (doesSomeExtensionReceiverContainsStubType) {
@@ -558,7 +558,7 @@ class DoubleColonExpressionResolver(
val dataFlowInfo = (lhs as? DoubleColonLHS.Expression)?.dataFlowInfo ?: c.dataFlowInfo
if (c.inferenceSession is BuilderInferenceSession && result?.contains { it is StubType } == true) {
if (c.inferenceSession is BuilderInferenceSession && result?.contains { it is StubTypeForBuilderInference } == true) {
c.inferenceSession.addOldCallableReferenceCalls(expression)
}