Don't lose inference session in all the possible locations

This commit is contained in:
Victor Petukhov
2021-03-19 15:14:22 +03:00
parent b5d3f9ee31
commit 80ac62864d
35 changed files with 567 additions and 210 deletions
@@ -16969,6 +16969,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/inference/builderInference"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/inference/builderInference"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
} }
@Test
@TestMetadata("builderCallAsReturnTypeInLocalClass.kt")
public void testBuilderCallAsReturnTypeInLocalClass() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/builderCallAsReturnTypeInLocalClass.kt");
}
@Test @Test
@TestMetadata("callableReferenceAndCoercionToUnit.kt") @TestMetadata("callableReferenceAndCoercionToUnit.kt")
public void testCallableReferenceAndCoercionToUnit() throws Exception { public void testCallableReferenceAndCoercionToUnit() throws Exception {
@@ -16987,18 +16993,6 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTest("compiler/testData/codegen/box/inference/builderInference/lackOfNullCheckOnNullableInsideBuild.kt"); runTest("compiler/testData/codegen/box/inference/builderInference/lackOfNullCheckOnNullableInsideBuild.kt");
} }
@Test
@TestMetadata("multiStepCompletionWithinThreeBuilderInferenceCalls.kt")
public void testMultiStepCompletionWithinThreeBuilderInferenceCalls() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/multiStepCompletionWithinThreeBuilderInferenceCalls.kt");
}
@Test
@TestMetadata("multiStepCompletionWithinTwoBuilderInferenceCalls.kt")
public void testMultiStepCompletionWithinTwoBuilderInferenceCalls() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/multiStepCompletionWithinTwoBuilderInferenceCalls.kt");
}
@Test @Test
@TestMetadata("propagateInferenceSessionIntoDeclarationAnalyzers.kt") @TestMetadata("propagateInferenceSessionIntoDeclarationAnalyzers.kt")
public void testPropagateInferenceSessionIntoDeclarationAnalyzers() throws Exception { public void testPropagateInferenceSessionIntoDeclarationAnalyzers() throws Exception {
@@ -17058,6 +17052,24 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
public void testSubstitutelambdaExtensionReceiverType() throws Exception { public void testSubstitutelambdaExtensionReceiverType() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/substitutelambdaExtensionReceiverType.kt"); runTest("compiler/testData/codegen/box/inference/builderInference/substitutelambdaExtensionReceiverType.kt");
} }
@Test
@TestMetadata("topDownCompletionBreakedByNonBuilderInferenceSession.kt")
public void testTopDownCompletionBreakedByNonBuilderInferenceSession() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/topDownCompletionBreakedByNonBuilderInferenceSession.kt");
}
@Test
@TestMetadata("topDownCompletionWithThreeBuilderInferenceCalls.kt")
public void testTopDownCompletionWithThreeBuilderInferenceCalls() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/topDownCompletionWithThreeBuilderInferenceCalls.kt");
}
@Test
@TestMetadata("topDownCompletionWithTwoBuilderInferenceCalls.kt")
public void testTopDownCompletionWithTwoBuilderInferenceCalls() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/topDownCompletionWithTwoBuilderInferenceCalls.kt");
}
} }
} }
@@ -73,12 +73,12 @@ open class PartialAnalysisHandlerExtension : AnalysisHandlerExtension {
ForceResolveUtil.forceResolveAllContents(descriptor.typeConstructor.supertypes) ForceResolveUtil.forceResolveAllContents(descriptor.typeConstructor.supertypes)
if (declaration is KtClassOrObject && descriptor is ClassDescriptorWithResolutionScopes) { if (declaration is KtClassOrObject && descriptor is ClassDescriptorWithResolutionScopes) {
bodyResolver.resolveSuperTypeEntryList(DataFlowInfo.EMPTY, bodyResolver.resolveSuperTypeEntryList(
declaration, DataFlowInfo.EMPTY, declaration, descriptor, descriptor.unsubstitutedPrimaryConstructor,
descriptor, descriptor.scopeForConstructorHeaderResolution,
descriptor.unsubstitutedPrimaryConstructor, descriptor.scopeForMemberDeclarationResolution,
descriptor.scopeForConstructorHeaderResolution, resolveSession.inferenceSession
descriptor.scopeForMemberDeclarationResolution) )
} }
} }
is PropertyDescriptor -> { is PropertyDescriptor -> {
@@ -99,7 +99,8 @@ open class PartialAnalysisHandlerExtension : AnalysisHandlerExtension {
if (containingScope != null) { if (containingScope != null) {
bodyResolver.resolveConstructorParameterDefaultValues( bodyResolver.resolveConstructorParameterDefaultValues(
topDownAnalysisContext.outerDataFlowInfo, bindingTrace, topDownAnalysisContext.outerDataFlowInfo, bindingTrace,
declaration, descriptor as ConstructorDescriptor, containingScope declaration, descriptor as ConstructorDescriptor, containingScope,
resolveSession.inferenceSession
) )
} }
} else if (declaration is KtFunction && !declaration.hasDeclaredReturnType() && !declaration.hasBlockBody()) { } else if (declaration is KtFunction && !declaration.hasDeclaredReturnType() && !declaration.hasBlockBody()) {
@@ -163,7 +163,8 @@ public class AnnotationResolverImpl extends AnnotationResolver {
CallMaker.makeCall(null, null, annotationEntry), CallMaker.makeCall(null, null, annotationEntry),
NO_EXPECTED_TYPE, NO_EXPECTED_TYPE,
DataFlowInfoFactory.EMPTY, DataFlowInfoFactory.EMPTY,
true true,
null // specific calls in terms of inference, can't be inside annotation calls
); );
} }
@@ -157,7 +157,8 @@ public class BodyResolver {
resolveFunctionBody( resolveFunctionBody(
outerDataFlowInfo, trace, constructor, descriptor, declaringScope, outerDataFlowInfo, trace, constructor, descriptor, declaringScope,
headerInnerScope -> resolveSecondaryConstructorDelegationCall( headerInnerScope -> resolveSecondaryConstructorDelegationCall(
outerDataFlowInfo, trace, headerInnerScope, constructor, descriptor outerDataFlowInfo, trace, headerInnerScope, constructor,
descriptor, localContext != null ? localContext.inferenceSession : null
), ),
scope -> new LexicalScopeImpl( scope -> new LexicalScopeImpl(
scope, descriptor, scope.isOwnerDescriptorAccessibleByLabel(), scope.getImplicitReceiver(), scope, descriptor, scope.isOwnerDescriptorAccessibleByLabel(), scope.getImplicitReceiver(),
@@ -173,7 +174,8 @@ public class BodyResolver {
@NotNull BindingTrace trace, @NotNull BindingTrace trace,
@NotNull LexicalScope scope, @NotNull LexicalScope scope,
@NotNull KtSecondaryConstructor constructor, @NotNull KtSecondaryConstructor constructor,
@NotNull ClassConstructorDescriptor descriptor @NotNull ClassConstructorDescriptor descriptor,
@Nullable InferenceSession inferenceSession
) { ) {
if (descriptor.isExpect() || isEffectivelyExternal(descriptor)) { if (descriptor.isExpect() || isEffectivelyExternal(descriptor)) {
// For expected and external classes, we do not resolve constructor delegation calls because they are prohibited // For expected and external classes, we do not resolve constructor delegation calls because they are prohibited
@@ -182,7 +184,7 @@ public class BodyResolver {
OverloadResolutionResults<?> results = callResolver.resolveConstructorDelegationCall( OverloadResolutionResults<?> results = callResolver.resolveConstructorDelegationCall(
trace, scope, outerDataFlowInfo, trace, scope, outerDataFlowInfo,
descriptor, constructor.getDelegationCall()); descriptor, constructor.getDelegationCall(), inferenceSession);
if (results != null && results.isSingleResult()) { if (results != null && results.isSingleResult()) {
ResolvedCall<? extends CallableDescriptor> resolvedCall = results.getResultingCall(); ResolvedCall<? extends CallableDescriptor> resolvedCall = results.getResultingCall();
@@ -260,11 +262,13 @@ public class BodyResolver {
for (Map.Entry<KtClassOrObject, ClassDescriptorWithResolutionScopes> entry : c.getDeclaredClasses().entrySet()) { for (Map.Entry<KtClassOrObject, ClassDescriptorWithResolutionScopes> entry : c.getDeclaredClasses().entrySet()) {
KtClassOrObject classOrObject = entry.getKey(); KtClassOrObject classOrObject = entry.getKey();
ClassDescriptorWithResolutionScopes descriptor = entry.getValue(); ClassDescriptorWithResolutionScopes descriptor = entry.getValue();
ExpressionTypingContext localContext = c.getLocalContext();
resolveSuperTypeEntryList(c.getOuterDataFlowInfo(), classOrObject, descriptor, resolveSuperTypeEntryList(c.getOuterDataFlowInfo(), classOrObject, descriptor,
descriptor.getUnsubstitutedPrimaryConstructor(), descriptor.getUnsubstitutedPrimaryConstructor(),
descriptor.getScopeForConstructorHeaderResolution(), descriptor.getScopeForConstructorHeaderResolution(),
descriptor.getScopeForMemberDeclarationResolution()); descriptor.getScopeForMemberDeclarationResolution(),
localContext != null ? localContext.inferenceSession : null);
} }
} }
@@ -274,7 +278,8 @@ public class BodyResolver {
@NotNull ClassDescriptor descriptor, @NotNull ClassDescriptor descriptor,
@Nullable ConstructorDescriptor primaryConstructor, @Nullable ConstructorDescriptor primaryConstructor,
@NotNull LexicalScope scopeForConstructorResolution, @NotNull LexicalScope scopeForConstructorResolution,
@NotNull LexicalScope scopeForMemberResolution @NotNull LexicalScope scopeForMemberResolution,
@Nullable InferenceSession inferenceSession
) { ) {
ProgressManager.checkCanceled(); ProgressManager.checkCanceled();
@@ -316,7 +321,8 @@ public class BodyResolver {
LexicalScope scope = scopeForConstructor == null ? scopeForMemberResolution : scopeForConstructor; LexicalScope scope = scopeForConstructor == null ? scopeForMemberResolution : scopeForConstructor;
KotlinType expectedType = supertype != null ? supertype : NO_EXPECTED_TYPE; KotlinType expectedType = supertype != null ? supertype : NO_EXPECTED_TYPE;
typeInferrer.getType( typeInferrer.getType(
scope, delegateExpression, expectedType, outerDataFlowInfo, InferenceSession.Companion.getDefault(), trace scope, delegateExpression, expectedType, outerDataFlowInfo,
inferenceSession != null ? inferenceSession : InferenceSession.Companion.getDefault(), trace
); );
} }
@@ -348,8 +354,9 @@ public class BodyResolver {
return; return;
} }
OverloadResolutionResults<FunctionDescriptor> results = callResolver.resolveFunctionCall( OverloadResolutionResults<FunctionDescriptor> results = callResolver.resolveFunctionCall(
trace, scopeForConstructor, trace, scopeForConstructor, CallMaker.makeConstructorCallWithoutTypeArguments(call),
CallMaker.makeConstructorCallWithoutTypeArguments(call), NO_EXPECTED_TYPE, outerDataFlowInfo, false); NO_EXPECTED_TYPE, outerDataFlowInfo, false, inferenceSession
);
if (results.isSingleResult()) { if (results.isSingleResult()) {
KotlinType supertype = results.getResultingDescriptor().getReturnType(); KotlinType supertype = results.getResultingDescriptor().getReturnType();
recordSupertype(typeReference, supertype); recordSupertype(typeReference, supertype);
@@ -404,8 +411,8 @@ public class BodyResolver {
if (ktClass instanceof KtEnumEntry && DescriptorUtils.isEnumEntry(descriptor) && ktClass.getSuperTypeListEntries().isEmpty()) { if (ktClass instanceof KtEnumEntry && DescriptorUtils.isEnumEntry(descriptor) && ktClass.getSuperTypeListEntries().isEmpty()) {
assert scopeForConstructor != null : "Scope for enum class constructor should be non-null: " + descriptor; assert scopeForConstructor != null : "Scope for enum class constructor should be non-null: " + descriptor;
resolveConstructorCallForEnumEntryWithoutInitializer( resolveConstructorCallForEnumEntryWithoutInitializer(
(KtEnumEntry) ktClass, descriptor, (KtEnumEntry) ktClass, descriptor, scopeForConstructor,
scopeForConstructor, outerDataFlowInfo, primaryConstructorDelegationCall outerDataFlowInfo, primaryConstructorDelegationCall, inferenceSession
); );
} }
@@ -450,7 +457,8 @@ public class BodyResolver {
@NotNull ClassDescriptor enumEntryDescriptor, @NotNull ClassDescriptor enumEntryDescriptor,
@NotNull LexicalScope scopeForConstructor, @NotNull LexicalScope scopeForConstructor,
@NotNull DataFlowInfo outerDataFlowInfo, @NotNull DataFlowInfo outerDataFlowInfo,
@NotNull ResolvedCall<?>[] primaryConstructorDelegationCall @NotNull ResolvedCall<?>[] primaryConstructorDelegationCall,
@Nullable InferenceSession inferenceSession
) { ) {
assert enumEntryDescriptor.getKind() == ClassKind.ENUM_ENTRY : "Enum entry expected: " + enumEntryDescriptor; assert enumEntryDescriptor.getKind() == ClassKind.ENUM_ENTRY : "Enum entry expected: " + enumEntryDescriptor;
ClassDescriptor enumClassDescriptor = (ClassDescriptor) enumEntryDescriptor.getContainingDeclaration(); ClassDescriptor enumClassDescriptor = (ClassDescriptor) enumEntryDescriptor.getContainingDeclaration();
@@ -468,8 +476,15 @@ public class BodyResolver {
Call call = CallMaker.makeConstructorCallWithoutTypeArguments(ktCallEntry); Call call = CallMaker.makeConstructorCallWithoutTypeArguments(ktCallEntry);
trace.record(BindingContext.TYPE, ktCallEntry.getTypeReference(), enumClassDescriptor.getDefaultType()); trace.record(BindingContext.TYPE, ktCallEntry.getTypeReference(), enumClassDescriptor.getDefaultType());
trace.record(BindingContext.CALL, ktEnumEntry, call); trace.record(BindingContext.CALL, ktEnumEntry, call);
OverloadResolutionResults<FunctionDescriptor> results = OverloadResolutionResults<FunctionDescriptor> results = callResolver.resolveFunctionCall(
callResolver.resolveFunctionCall(trace, scopeForConstructor, call, NO_EXPECTED_TYPE, outerDataFlowInfo, false); trace,
scopeForConstructor,
call,
NO_EXPECTED_TYPE,
outerDataFlowInfo,
false,
inferenceSession
);
if (primaryConstructorDelegationCall[0] == null) { if (primaryConstructorDelegationCall[0] == null) {
primaryConstructorDelegationCall[0] = results.getResultingCall(); primaryConstructorDelegationCall[0] = results.getResultingCall();
} }
@@ -666,14 +681,16 @@ public class BodyResolver {
for (Map.Entry<KtAnonymousInitializer, ClassDescriptorWithResolutionScopes> entry : c.getAnonymousInitializers().entrySet()) { for (Map.Entry<KtAnonymousInitializer, ClassDescriptorWithResolutionScopes> entry : c.getAnonymousInitializers().entrySet()) {
KtAnonymousInitializer initializer = entry.getKey(); KtAnonymousInitializer initializer = entry.getKey();
ClassDescriptorWithResolutionScopes descriptor = entry.getValue(); ClassDescriptorWithResolutionScopes descriptor = entry.getValue();
resolveAnonymousInitializer(c.getOuterDataFlowInfo(), initializer, descriptor); ExpressionTypingContext context = c.getLocalContext();
resolveAnonymousInitializer(c.getOuterDataFlowInfo(), initializer, descriptor, context != null ? context.inferenceSession : null);
} }
} }
public void resolveAnonymousInitializer( public void resolveAnonymousInitializer(
@NotNull DataFlowInfo outerDataFlowInfo, @NotNull DataFlowInfo outerDataFlowInfo,
@NotNull KtAnonymousInitializer anonymousInitializer, @NotNull KtAnonymousInitializer anonymousInitializer,
@NotNull ClassDescriptorWithResolutionScopes classDescriptor @NotNull ClassDescriptorWithResolutionScopes classDescriptor,
@Nullable InferenceSession inferenceSession
) { ) {
ProgressManager.checkCanceled(); ProgressManager.checkCanceled();
@@ -684,7 +701,7 @@ public class BodyResolver {
(KtDeclaration) anonymousInitializer.getParent().getParent(), trace, languageVersionSettings); (KtDeclaration) anonymousInitializer.getParent().getParent(), trace, languageVersionSettings);
expressionTypingServices.getTypeInfo( expressionTypingServices.getTypeInfo(
scopeForInitializers, body, NO_EXPECTED_TYPE, outerDataFlowInfo, scopeForInitializers, body, NO_EXPECTED_TYPE, outerDataFlowInfo,
InferenceSession.Companion.getDefault(), trace, /*isStatement = */true inferenceSession != null ? inferenceSession : InferenceSession.Companion.getDefault(), trace, /*isStatement = */true
); );
} }
processModifiersOnInitializer(anonymousInitializer, scopeForInitializers); processModifiersOnInitializer(anonymousInitializer, scopeForInitializers);
@@ -713,11 +730,13 @@ public class BodyResolver {
if (unsubstitutedPrimaryConstructor != null) { if (unsubstitutedPrimaryConstructor != null) {
ForceResolveUtil.forceResolveAllContents(unsubstitutedPrimaryConstructor.getAnnotations()); ForceResolveUtil.forceResolveAllContents(unsubstitutedPrimaryConstructor.getAnnotations());
ExpressionTypingContext localContext = c.getLocalContext();
LexicalScope parameterScope = getPrimaryConstructorParametersScope(classDescriptor.getScopeForConstructorHeaderResolution(), LexicalScope parameterScope = getPrimaryConstructorParametersScope(classDescriptor.getScopeForConstructorHeaderResolution(),
unsubstitutedPrimaryConstructor); unsubstitutedPrimaryConstructor);
valueParameterResolver.resolveValueParameters(klass.getPrimaryConstructorParameters(), valueParameterResolver.resolveValueParameters(
unsubstitutedPrimaryConstructor.getValueParameters(), klass.getPrimaryConstructorParameters(), unsubstitutedPrimaryConstructor.getValueParameters(),
parameterScope, c.getOuterDataFlowInfo(), trace); parameterScope, c.getOuterDataFlowInfo(), trace, localContext != null ? localContext.inferenceSession : null
);
// Annotations on value parameter and constructor parameter could be splitted // Annotations on value parameter and constructor parameter could be splitted
resolveConstructorPropertyDescriptors(klass); resolveConstructorPropertyDescriptors(klass);
} }
@@ -769,15 +788,22 @@ public class BodyResolver {
PreliminaryDeclarationVisitor.Companion.createForDeclaration(property, trace, languageVersionSettings); PreliminaryDeclarationVisitor.Companion.createForDeclaration(property, trace, languageVersionSettings);
KtExpression initializer = property.getInitializer(); KtExpression initializer = property.getInitializer();
LexicalScope propertyHeaderScope = ScopeUtils.makeScopeForPropertyHeader(getScopeForProperty(c, property), propertyDescriptor); LexicalScope propertyHeaderScope = ScopeUtils.makeScopeForPropertyHeader(getScopeForProperty(c, property), propertyDescriptor);
ExpressionTypingContext context = c.getLocalContext();
if (initializer != null) { if (initializer != null) {
resolvePropertyInitializer(c.getOuterDataFlowInfo(), property, propertyDescriptor, initializer, propertyHeaderScope); resolvePropertyInitializer(
c.getOuterDataFlowInfo(), property, propertyDescriptor,
initializer, propertyHeaderScope, context != null ? context.inferenceSession : null
);
} }
KtExpression delegateExpression = property.getDelegateExpression(); KtExpression delegateExpression = property.getDelegateExpression();
if (delegateExpression != null) { if (delegateExpression != null) {
assert initializer == null : "Initializer should be null for delegated property : " + property.getText(); assert initializer == null : "Initializer should be null for delegated property : " + property.getText();
resolvePropertyDelegate(c.getOuterDataFlowInfo(), property, propertyDescriptor, delegateExpression, propertyHeaderScope); resolvePropertyDelegate(
c.getOuterDataFlowInfo(), property, propertyDescriptor,
delegateExpression, propertyHeaderScope, context != null ? context.inferenceSession : null
);
} }
resolvePropertyAccessors(c, property, propertyDescriptor); resolvePropertyAccessors(c, property, propertyDescriptor);
@@ -881,14 +907,15 @@ public class BodyResolver {
@NotNull KtProperty property, @NotNull KtProperty property,
@NotNull PropertyDescriptor propertyDescriptor, @NotNull PropertyDescriptor propertyDescriptor,
@NotNull KtExpression delegateExpression, @NotNull KtExpression delegateExpression,
@NotNull LexicalScope propertyHeaderScope @NotNull LexicalScope propertyHeaderScope,
@Nullable InferenceSession inferenceSession
) { ) {
delegatedPropertyResolver.resolvePropertyDelegate(outerDataFlowInfo, delegatedPropertyResolver.resolvePropertyDelegate(outerDataFlowInfo,
property, property,
propertyDescriptor, propertyDescriptor,
delegateExpression, delegateExpression,
propertyHeaderScope, propertyHeaderScope,
InferenceSession.Companion.getDefault(), inferenceSession != null ? inferenceSession : InferenceSession.Companion.getDefault(),
trace); trace);
} }
@@ -897,13 +924,16 @@ public class BodyResolver {
@NotNull KtProperty property, @NotNull KtProperty property,
@NotNull PropertyDescriptor propertyDescriptor, @NotNull PropertyDescriptor propertyDescriptor,
@NotNull KtExpression initializer, @NotNull KtExpression initializer,
@NotNull LexicalScope propertyHeader @NotNull LexicalScope propertyHeader,
@Nullable InferenceSession inferenceSession
) { ) {
LexicalScope propertyDeclarationInnerScope = ScopeUtils.makeScopeForPropertyInitializer(propertyHeader, propertyDescriptor); LexicalScope propertyDeclarationInnerScope = ScopeUtils.makeScopeForPropertyInitializer(propertyHeader, propertyDescriptor);
KotlinType expectedTypeForInitializer = property.getTypeReference() != null ? propertyDescriptor.getType() : NO_EXPECTED_TYPE; KotlinType expectedTypeForInitializer = property.getTypeReference() != null ? propertyDescriptor.getType() : NO_EXPECTED_TYPE;
if (propertyDescriptor.getCompileTimeInitializer() == null) { if (propertyDescriptor.getCompileTimeInitializer() == null) {
expressionTypingServices.getType(propertyDeclarationInnerScope, initializer, expectedTypeForInitializer, expressionTypingServices.getType(
outerDataFlowInfo, InferenceSession.Companion.getDefault(), trace); propertyDeclarationInnerScope, initializer, expectedTypeForInitializer,
outerDataFlowInfo, inferenceSession != null ? inferenceSession : InferenceSession.Companion.getDefault(), trace
);
} }
} }
@@ -966,7 +996,8 @@ public class BodyResolver {
LexicalScope headerScope = headerScopeFactory != null ? headerScopeFactory.invoke(innerScope) : innerScope; LexicalScope headerScope = headerScopeFactory != null ? headerScopeFactory.invoke(innerScope) : innerScope;
valueParameterResolver.resolveValueParameters( valueParameterResolver.resolveValueParameters(
valueParameters, valueParameterDescriptors, headerScope, outerDataFlowInfo, trace valueParameters, valueParameterDescriptors, headerScope, outerDataFlowInfo, trace,
localContext != null ? localContext.inferenceSession : null
); );
// Synthetic "field" creation // Synthetic "field" creation
@@ -1008,14 +1039,15 @@ public class BodyResolver {
@NotNull BindingTrace trace, @NotNull BindingTrace trace,
@NotNull KtPrimaryConstructor constructor, @NotNull KtPrimaryConstructor constructor,
@NotNull ConstructorDescriptor constructorDescriptor, @NotNull ConstructorDescriptor constructorDescriptor,
@NotNull LexicalScope declaringScope @NotNull LexicalScope declaringScope,
@Nullable InferenceSession inferenceSession
) { ) {
List<KtParameter> valueParameters = constructor.getValueParameters(); List<KtParameter> valueParameters = constructor.getValueParameters();
List<ValueParameterDescriptor> valueParameterDescriptors = constructorDescriptor.getValueParameters(); List<ValueParameterDescriptor> valueParameterDescriptors = constructorDescriptor.getValueParameters();
LexicalScope scope = getPrimaryConstructorParametersScope(declaringScope, constructorDescriptor); LexicalScope scope = getPrimaryConstructorParametersScope(declaringScope, constructorDescriptor);
valueParameterResolver.resolveValueParameters(valueParameters, valueParameterDescriptors, scope, outerDataFlowInfo, trace); valueParameterResolver.resolveValueParameters(valueParameters, valueParameterDescriptors, scope, outerDataFlowInfo, trace, inferenceSession);
} }
public static void computeDeferredType(KotlinType type) { public static void computeDeferredType(KotlinType type) {
@@ -94,10 +94,14 @@ class DelegatedPropertyResolver(
delegateExpression, property, variableDescriptor, initializerScope, trace, outerDataFlowInfo, inferenceSession delegateExpression, property, variableDescriptor, initializerScope, trace, outerDataFlowInfo, inferenceSession
) )
resolveProvideDelegateMethod(variableDescriptor, delegateExpression, byExpressionType, trace, initializerScope, outerDataFlowInfo) resolveProvideDelegateMethod(
variableDescriptor, delegateExpression, byExpressionType, trace, initializerScope, outerDataFlowInfo, inferenceSession
)
val delegateType = getResolvedDelegateType(variableDescriptor, delegateExpression, byExpressionType, trace) val delegateType = getResolvedDelegateType(variableDescriptor, delegateExpression, byExpressionType, trace)
resolveGetValueMethod(variableDescriptor, delegateExpression, delegateType, trace, initializerScope, outerDataFlowInfo) resolveGetValueMethod(
variableDescriptor, delegateExpression, delegateType, trace, initializerScope, outerDataFlowInfo, inferenceSession
)
if (property.isVar) { if (property.isVar) {
resolveSetValueMethod(variableDescriptor, delegateExpression, delegateType, trace, initializerScope, outerDataFlowInfo) resolveSetValueMethod(variableDescriptor, delegateExpression, delegateType, trace, initializerScope, outerDataFlowInfo)
} }
@@ -123,9 +127,12 @@ class DelegatedPropertyResolver(
byExpressionType: KotlinType, byExpressionType: KotlinType,
trace: BindingTrace, trace: BindingTrace,
initializerScope: LexicalScope, initializerScope: LexicalScope,
dataFlowInfo: DataFlowInfo dataFlowInfo: DataFlowInfo,
inferenceSession: InferenceSession
): KotlinType? { ): KotlinType? {
resolveProvideDelegateMethod(variableDescriptor, delegateExpression, byExpressionType, trace, initializerScope, dataFlowInfo) resolveProvideDelegateMethod(
variableDescriptor, delegateExpression, byExpressionType, trace, initializerScope, dataFlowInfo, inferenceSession
)
val delegateType = getResolvedDelegateType(variableDescriptor, delegateExpression, byExpressionType, trace) val delegateType = getResolvedDelegateType(variableDescriptor, delegateExpression, byExpressionType, trace)
resolveGetSetValueMethod(variableDescriptor, delegateExpression, delegateType, trace, initializerScope, dataFlowInfo, true) resolveGetSetValueMethod(variableDescriptor, delegateExpression, delegateType, trace, initializerScope, dataFlowInfo, true)
@@ -142,10 +149,12 @@ class DelegatedPropertyResolver(
delegateType: KotlinType, delegateType: KotlinType,
trace: BindingTrace, trace: BindingTrace,
initializerScope: LexicalScope, initializerScope: LexicalScope,
dataFlowInfo: DataFlowInfo dataFlowInfo: DataFlowInfo,
inferenceSession: InferenceSession
) { ) {
val returnType = val returnType = getGetValueMethodReturnType(
getGetValueMethodReturnType(variableDescriptor, delegateExpression, delegateType, trace, initializerScope, dataFlowInfo) variableDescriptor, delegateExpression, delegateType, trace, initializerScope, dataFlowInfo, inferenceSession
)
val propertyType = variableDescriptor.type val propertyType = variableDescriptor.type
/* Do not check return type of get() method of delegate for properties with DeferredType because property type is taken from it */ /* Do not check return type of get() method of delegate for properties with DeferredType because property type is taken from it */
@@ -288,7 +297,8 @@ class DelegatedPropertyResolver(
byExpressionType: KotlinType, byExpressionType: KotlinType,
trace: BindingTrace, trace: BindingTrace,
initializerScope: LexicalScope, initializerScope: LexicalScope,
dataFlowInfo: DataFlowInfo dataFlowInfo: DataFlowInfo,
inferenceSession: InferenceSession
) { ) {
if (!isOperatorProvideDelegateSupported) return if (!isOperatorProvideDelegateSupported) return
if (trace.bindingContext.get(PROVIDE_DELEGATE_CALL, propertyDescriptor) != null) return if (trace.bindingContext.get(PROVIDE_DELEGATE_CALL, propertyDescriptor) != null) return
@@ -297,7 +307,7 @@ class DelegatedPropertyResolver(
val provideDelegateResults = getProvideDelegateMethod( val provideDelegateResults = getProvideDelegateMethod(
propertyDescriptor, byExpression, byExpressionType, propertyDescriptor, byExpression, byExpressionType,
traceForProvideDelegate, initializerScope, dataFlowInfo traceForProvideDelegate, initializerScope, dataFlowInfo, inferenceSession
) )
if (!provideDelegateResults.isSuccess) { if (!provideDelegateResults.isSuccess) {
val call = traceForProvideDelegate.bindingContext.get(PROVIDE_DELEGATE_CALL, propertyDescriptor) val call = traceForProvideDelegate.bindingContext.get(PROVIDE_DELEGATE_CALL, propertyDescriptor)
@@ -421,7 +431,8 @@ class DelegatedPropertyResolver(
delegateExpressionType: KotlinType, delegateExpressionType: KotlinType,
trace: BindingTrace, trace: BindingTrace,
initializerScope: LexicalScope, initializerScope: LexicalScope,
dataFlowInfo: DataFlowInfo dataFlowInfo: DataFlowInfo,
inferenceSession: InferenceSession?
): OverloadResolutionResults<FunctionDescriptor> { ): OverloadResolutionResults<FunctionDescriptor> {
val context = ExpressionTypingContext.newContext( val context = ExpressionTypingContext.newContext(
trace, trace,
@@ -429,7 +440,8 @@ class DelegatedPropertyResolver(
dataFlowInfo, dataFlowInfo,
NO_EXPECTED_TYPE, NO_EXPECTED_TYPE,
languageVersionSettings, languageVersionSettings,
dataFlowValueFactory dataFlowValueFactory,
inferenceSession
) )
return getProvideDelegateMethod(propertyDescriptor, delegateExpression, delegateExpressionType, context) return getProvideDelegateMethod(propertyDescriptor, delegateExpression, delegateExpressionType, context)
} }
@@ -567,7 +579,8 @@ class DelegatedPropertyResolver(
val delegateTypeWithoutNonFixedVariables = nonFixedVariablesToStubTypesSubstitutor.safeSubstitute(delegateType.unwrap()) val delegateTypeWithoutNonFixedVariables = nonFixedVariablesToStubTypesSubstitutor.safeSubstitute(delegateType.unwrap())
val contextForProvideDelegate = createContextForProvideDelegateMethod( val contextForProvideDelegate = createContextForProvideDelegateMethod(
scopeForDelegate, delegateDataFlow, traceForProvideDelegate, InferenceSessionForExistingCandidates(substitutionMap != null) scopeForDelegate, delegateDataFlow, traceForProvideDelegate,
InferenceSessionForExistingCandidates(substitutionMap != null)
) )
val provideDelegateResults = getProvideDelegateMethod( val provideDelegateResults = getProvideDelegateMethod(
@@ -589,7 +602,7 @@ class DelegatedPropertyResolver(
return inferDelegateTypeFromGetSetValueMethods( return inferDelegateTypeFromGetSetValueMethods(
delegateExpression, variableDescriptor, scopeForDelegate, delegateExpression, variableDescriptor, scopeForDelegate,
traceToResolveDelegatedProperty, delegateType, delegateTypeForProperType, traceToResolveDelegatedProperty, delegateType, delegateTypeForProperType,
delegateDataFlow delegateDataFlow, inferenceSession
) )
} }
@@ -632,10 +645,11 @@ class DelegatedPropertyResolver(
trace: TemporaryBindingTrace, trace: TemporaryBindingTrace,
delegateType: KotlinType, delegateType: KotlinType,
delegateTypeForProperType: KotlinType?, delegateTypeForProperType: KotlinType?,
delegateDataFlow: DataFlowInfo delegateDataFlow: DataFlowInfo,
inferenceSession: InferenceSession
): UnwrappedType { ): UnwrappedType {
val expectedType = if (variableDescriptor.type !is DeferredType) variableDescriptor.type.unwrap() else null val expectedType = if (variableDescriptor.type !is DeferredType) variableDescriptor.type.unwrap() else null
val inferenceSession = DelegatedPropertyInferenceSession( val newInferenceSession = DelegatedPropertyInferenceSession(
variableDescriptor, expectedType, psiCallResolver, variableDescriptor, expectedType, psiCallResolver,
postponedArgumentsAnalyzer, kotlinConstraintSystemCompleter, postponedArgumentsAnalyzer, kotlinConstraintSystemCompleter,
callComponents, builtIns callComponents, builtIns
@@ -643,7 +657,7 @@ class DelegatedPropertyResolver(
val receiver = createReceiverForGetSetValueMethods(delegateExpression, delegateType, trace) val receiver = createReceiverForGetSetValueMethods(delegateExpression, delegateType, trace)
val context = createContextForGetSetValueMethods( val context = createContextForGetSetValueMethods(
variableDescriptor, scopeForDelegate, delegateDataFlow, trace, inferenceSession variableDescriptor, scopeForDelegate, delegateDataFlow, trace, newInferenceSession
) )
fun recordResolvedDelegateOrReportError( fun recordResolvedDelegateOrReportError(
@@ -678,8 +692,8 @@ class DelegatedPropertyResolver(
) )
} }
val resolutionCallbacks = psiCallResolver.createResolutionCallbacks(trace, inferenceSession, context = null) val resolutionCallbacks = psiCallResolver.createResolutionCallbacks(trace, newInferenceSession, context = null)
val resolutionResults = inferenceSession.resolveCandidates(resolutionCallbacks) val resolutionResults = newInferenceSession.resolveCandidates(resolutionCallbacks)
for ((name, isGet) in listOf(OperatorNameConventions.GET_VALUE to true, OperatorNameConventions.SET_VALUE to false)) { for ((name, isGet) in listOf(OperatorNameConventions.GET_VALUE to true, OperatorNameConventions.SET_VALUE to false)) {
val result = resolutionResults.firstOrNull { val result = resolutionResults.firstOrNull {
@@ -779,7 +793,8 @@ class DelegatedPropertyResolver(
if (isOperatorProvideDelegateSupported) { if (isOperatorProvideDelegateSupported) {
val provideDelegateResults = getProvideDelegateMethod( val provideDelegateResults = getProvideDelegateMethod(
variableDescriptor, delegateExpression, byExpressionType, variableDescriptor, delegateExpression, byExpressionType,
traceToResolveConventionMethods, scopeForDelegate, dataFlowInfo traceToResolveConventionMethods, scopeForDelegate,
dataFlowInfo, null // it's used only from the old type inference
) )
if (conventionMethodFound(provideDelegateResults)) { if (conventionMethodFound(provideDelegateResults)) {
val provideDelegateDescriptor = provideDelegateResults.resultingDescriptor val provideDelegateDescriptor = provideDelegateResults.resultingDescriptor
@@ -307,7 +307,8 @@ public class DescriptorResolver {
int index, int index,
@NotNull KotlinType type, @NotNull KotlinType type,
@NotNull BindingTrace trace, @NotNull BindingTrace trace,
@NotNull Annotations additionalAnnotations @NotNull Annotations additionalAnnotations,
@Nullable InferenceSession inferenceSession
) { ) {
KotlinType varargElementType = null; KotlinType varargElementType = null;
KotlinType variableType = type; KotlinType variableType = type;
@@ -340,7 +341,7 @@ public class DescriptorResolver {
destructuringDeclaration, new TransientReceiver(type), /* initializer = */ null, destructuringDeclaration, new TransientReceiver(type), /* initializer = */ null,
ExpressionTypingContext.newContext( ExpressionTypingContext.newContext(
trace, scopeForDestructuring, DataFlowInfoFactory.EMPTY, TypeUtils.NO_EXPECTED_TYPE, trace, scopeForDestructuring, DataFlowInfoFactory.EMPTY, TypeUtils.NO_EXPECTED_TYPE,
languageVersionSettings, dataFlowValueFactory languageVersionSettings, dataFlowValueFactory, inferenceSession
) )
); );
@@ -813,7 +814,8 @@ public class DescriptorResolver {
KtExpression initializer = destructuringDeclaration.getInitializer(); KtExpression initializer = destructuringDeclaration.getInitializer();
ExpressionTypingContext context = ExpressionTypingContext.newContext( ExpressionTypingContext context = ExpressionTypingContext.newContext(
trace, scopeForDeclarationResolution, dataFlowInfo, TypeUtils.NO_EXPECTED_TYPE, languageVersionSettings, dataFlowValueFactory trace, scopeForDeclarationResolution, dataFlowInfo, TypeUtils.NO_EXPECTED_TYPE,
languageVersionSettings, dataFlowValueFactory, inferenceSession
); );
ExpressionReceiver receiver = createReceiverForDestructuringDeclaration(destructuringDeclaration, context); ExpressionReceiver receiver = createReceiverForDestructuringDeclaration(destructuringDeclaration, context);
@@ -874,7 +876,7 @@ public class DescriptorResolver {
@NotNull KtVariableDeclaration variableDeclaration, @NotNull KtVariableDeclaration variableDeclaration,
@NotNull BindingTrace trace, @NotNull BindingTrace trace,
@NotNull DataFlowInfo dataFlowInfo, @NotNull DataFlowInfo dataFlowInfo,
@NotNull InferenceSession inferenceSession, @Nullable InferenceSession inferenceSession,
@NotNull VariableAsPropertyInfo propertyInfo @NotNull VariableAsPropertyInfo propertyInfo
) { ) {
KtModifierList modifierList = variableDeclaration.getModifierList(); KtModifierList modifierList = variableDeclaration.getModifierList();
@@ -987,7 +989,9 @@ public class DescriptorResolver {
trace, trace,
typeIfKnown, typeIfKnown,
propertyInfo.getPropertyGetter(), propertyInfo.getPropertyGetter(),
propertyInfo.getHasDelegate()); propertyInfo.getHasDelegate(),
inferenceSession
);
KotlinType type = typeIfKnown != null ? typeIfKnown : getter.getReturnType(); KotlinType type = typeIfKnown != null ? typeIfKnown : getter.getReturnType();
@@ -1006,7 +1010,9 @@ public class DescriptorResolver {
annotationSplitter, annotationSplitter,
trace, trace,
propertyInfo.getPropertySetter(), propertyInfo.getPropertySetter(),
propertyInfo.getHasDelegate()); propertyInfo.getHasDelegate(),
inferenceSession
);
propertyDescriptor.initialize( propertyDescriptor.initialize(
getter, setter, getter, setter,
@@ -1064,7 +1070,8 @@ public class DescriptorResolver {
@NotNull AnnotationSplitter annotationSplitter, @NotNull AnnotationSplitter annotationSplitter,
@NotNull BindingTrace trace, @NotNull BindingTrace trace,
@Nullable KtPropertyAccessor setter, @Nullable KtPropertyAccessor setter,
boolean hasDelegate boolean hasDelegate,
@Nullable InferenceSession inferenceSession
) { ) {
PropertySetterDescriptorImpl setterDescriptor = null; PropertySetterDescriptorImpl setterDescriptor = null;
Annotations setterTargetedAnnotations = annotationSplitter.getAnnotationsForTarget(PROPERTY_SETTER); Annotations setterTargetedAnnotations = annotationSplitter.getAnnotationsForTarget(PROPERTY_SETTER);
@@ -1114,7 +1121,7 @@ public class DescriptorResolver {
} }
ValueParameterDescriptorImpl valueParameterDescriptor = resolveValueParameterDescriptor( ValueParameterDescriptorImpl valueParameterDescriptor = resolveValueParameterDescriptor(
scopeWithTypeParameters, setterDescriptor, parameter, 0, type, trace, parameterTargetedAnnotations scopeWithTypeParameters, setterDescriptor, parameter, 0, type, trace, parameterTargetedAnnotations, inferenceSession
); );
setterDescriptor.initialize(valueParameterDescriptor); setterDescriptor.initialize(valueParameterDescriptor);
} }
@@ -1150,7 +1157,8 @@ public class DescriptorResolver {
@NotNull BindingTrace trace, @NotNull BindingTrace trace,
@Nullable KotlinType propertyTypeIfKnown, @Nullable KotlinType propertyTypeIfKnown,
@Nullable KtPropertyAccessor getter, @Nullable KtPropertyAccessor getter,
boolean hasDelegate boolean hasDelegate,
@Nullable InferenceSession inferenceSession
) { ) {
PropertyGetterDescriptorImpl getterDescriptor; PropertyGetterDescriptorImpl getterDescriptor;
KotlinType getterType; KotlinType getterType;
@@ -1170,7 +1178,9 @@ public class DescriptorResolver {
property.hasModifier(KtTokens.INLINE_KEYWORD) || getter.hasModifier(KtTokens.INLINE_KEYWORD), property.hasModifier(KtTokens.INLINE_KEYWORD) || getter.hasModifier(KtTokens.INLINE_KEYWORD),
CallableMemberDescriptor.Kind.DECLARATION, null, KotlinSourceElementKt.toSourceElement(getter) CallableMemberDescriptor.Kind.DECLARATION, null, KotlinSourceElementKt.toSourceElement(getter)
); );
getterType = determineGetterReturnType(scopeForDeclarationResolution, trace, getterDescriptor, getter, propertyTypeIfKnown); getterType = determineGetterReturnType(
scopeForDeclarationResolution, trace, getterDescriptor, getter, propertyTypeIfKnown, inferenceSession
);
trace.record(BindingContext.PROPERTY_ACCESSOR, getter, getterDescriptor); trace.record(BindingContext.PROPERTY_ACCESSOR, getter, getterDescriptor);
} }
else { else {
@@ -1193,7 +1203,8 @@ public class DescriptorResolver {
@NotNull BindingTrace trace, @NotNull BindingTrace trace,
@NotNull PropertyGetterDescriptor getterDescriptor, @NotNull PropertyGetterDescriptor getterDescriptor,
@NotNull KtPropertyAccessor getter, @NotNull KtPropertyAccessor getter,
@Nullable KotlinType propertyTypeIfKnown @Nullable KotlinType propertyTypeIfKnown,
@Nullable InferenceSession inferenceSession
) { ) {
KtTypeReference returnTypeReference = getter.getReturnTypeReference(); KtTypeReference returnTypeReference = getter.getReturnTypeReference();
if (returnTypeReference != null) { if (returnTypeReference != null) {
@@ -1210,7 +1221,7 @@ public class DescriptorResolver {
KtProperty property = getter.getProperty(); KtProperty property = getter.getProperty();
if (!property.hasDelegateExpressionOrInitializer() && property.getTypeReference() == null && if (!property.hasDelegateExpressionOrInitializer() && property.getTypeReference() == null &&
getter.hasBody() && !getter.hasBlockBody()) { getter.hasBody() && !getter.hasBlockBody()) {
return inferReturnTypeFromExpressionBody(trace, scope, DataFlowInfoFactory.EMPTY, getter, getterDescriptor); return inferReturnTypeFromExpressionBody(trace, scope, DataFlowInfoFactory.EMPTY, getter, getterDescriptor, inferenceSession);
} }
return propertyTypeIfKnown; return propertyTypeIfKnown;
@@ -1222,11 +1233,14 @@ public class DescriptorResolver {
@NotNull LexicalScope scope, @NotNull LexicalScope scope,
@NotNull DataFlowInfo dataFlowInfo, @NotNull DataFlowInfo dataFlowInfo,
@NotNull KtDeclarationWithBody function, @NotNull KtDeclarationWithBody function,
@NotNull FunctionDescriptor functionDescriptor @NotNull FunctionDescriptor functionDescriptor,
@Nullable InferenceSession inferenceSession
) { ) {
return wrappedTypeFactory.createRecursionIntolerantDeferredType(trace, () -> { return wrappedTypeFactory.createRecursionIntolerantDeferredType(trace, () -> {
PreliminaryDeclarationVisitor.Companion.createForDeclaration(function, trace, languageVersionSettings); PreliminaryDeclarationVisitor.Companion.createForDeclaration(function, trace, languageVersionSettings);
KotlinType type = expressionTypingServices.getBodyExpressionType(trace, scope, dataFlowInfo, function, functionDescriptor); KotlinType type = expressionTypingServices.getBodyExpressionType(
trace, scope, dataFlowInfo, function, functionDescriptor, inferenceSession
);
KotlinType publicType = transformAnonymousTypeIfNeeded( KotlinType publicType = transformAnonymousTypeIfNeeded(
functionDescriptor, function, type, trace, anonymousTypeTransformers, languageVersionSettings functionDescriptor, function, type, trace, anonymousTypeTransformers, languageVersionSettings
); );
@@ -47,6 +47,7 @@ import org.jetbrains.kotlin.resolve.ModifiersChecker.resolveMemberModalityFromMo
import org.jetbrains.kotlin.resolve.ModifiersChecker.resolveVisibilityFromModifiers import org.jetbrains.kotlin.resolve.ModifiersChecker.resolveVisibilityFromModifiers
import org.jetbrains.kotlin.resolve.bindingContextUtil.recordScope import org.jetbrains.kotlin.resolve.bindingContextUtil.recordScope
import org.jetbrains.kotlin.resolve.calls.DslMarkerUtils import org.jetbrains.kotlin.resolve.calls.DslMarkerUtils
import org.jetbrains.kotlin.resolve.calls.components.InferenceSession
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
import org.jetbrains.kotlin.resolve.calls.util.createValueParametersForInvokeInFunctionType import org.jetbrains.kotlin.resolve.calls.util.createValueParametersForInvokeInFunctionType
import org.jetbrains.kotlin.resolve.lazy.ForceResolveUtil import org.jetbrains.kotlin.resolve.lazy.ForceResolveUtil
@@ -84,12 +85,14 @@ class FunctionDescriptorResolver(
scope: LexicalScope, scope: LexicalScope,
function: KtNamedFunction, function: KtNamedFunction,
trace: BindingTrace, trace: BindingTrace,
dataFlowInfo: DataFlowInfo dataFlowInfo: DataFlowInfo,
inferenceSession: InferenceSession?
): SimpleFunctionDescriptor { ): SimpleFunctionDescriptor {
if (function.name == null) trace.report(FUNCTION_DECLARATION_WITH_NO_NAME.on(function)) if (function.name == null) trace.report(FUNCTION_DECLARATION_WITH_NO_NAME.on(function))
return resolveFunctionDescriptor( return resolveFunctionDescriptor(
SimpleFunctionDescriptorImpl::create, containingDescriptor, scope, function, trace, dataFlowInfo, TypeUtils.NO_EXPECTED_TYPE SimpleFunctionDescriptorImpl::create, containingDescriptor, scope,
function, trace, dataFlowInfo, TypeUtils.NO_EXPECTED_TYPE, inferenceSession
) )
} }
@@ -100,9 +103,10 @@ class FunctionDescriptorResolver(
function: KtNamedFunction, function: KtNamedFunction,
trace: BindingTrace, trace: BindingTrace,
dataFlowInfo: DataFlowInfo, dataFlowInfo: DataFlowInfo,
expectedFunctionType: KotlinType expectedFunctionType: KotlinType,
inferenceSession: InferenceSession?
): SimpleFunctionDescriptor = resolveFunctionDescriptor( ): SimpleFunctionDescriptor = resolveFunctionDescriptor(
::FunctionExpressionDescriptor, containingDescriptor, scope, function, trace, dataFlowInfo, expectedFunctionType ::FunctionExpressionDescriptor, containingDescriptor, scope, function, trace, dataFlowInfo, expectedFunctionType, inferenceSession
) )
private fun resolveFunctionDescriptor( private fun resolveFunctionDescriptor(
@@ -112,7 +116,8 @@ class FunctionDescriptorResolver(
function: KtNamedFunction, function: KtNamedFunction,
trace: BindingTrace, trace: BindingTrace,
dataFlowInfo: DataFlowInfo, dataFlowInfo: DataFlowInfo,
expectedFunctionType: KotlinType expectedFunctionType: KotlinType,
inferenceSession: InferenceSession?
): SimpleFunctionDescriptor { ): SimpleFunctionDescriptor {
val functionDescriptor = functionConstructor( val functionDescriptor = functionConstructor(
containingDescriptor, containingDescriptor,
@@ -128,9 +133,10 @@ class FunctionDescriptorResolver(
functionDescriptor, functionDescriptor,
trace, trace,
expectedFunctionType, expectedFunctionType,
dataFlowInfo dataFlowInfo,
inferenceSession
) )
initializeFunctionReturnTypeBasedOnFunctionBody(scope, function, functionDescriptor, trace, dataFlowInfo) initializeFunctionReturnTypeBasedOnFunctionBody(scope, function, functionDescriptor, trace, dataFlowInfo, inferenceSession)
BindingContextUtils.recordFunctionDeclarationToDescriptor(trace, function, functionDescriptor) BindingContextUtils.recordFunctionDeclarationToDescriptor(trace, function, functionDescriptor)
return functionDescriptor return functionDescriptor
} }
@@ -140,7 +146,8 @@ class FunctionDescriptorResolver(
function: KtNamedFunction, function: KtNamedFunction,
functionDescriptor: SimpleFunctionDescriptorImpl, functionDescriptor: SimpleFunctionDescriptorImpl,
trace: BindingTrace, trace: BindingTrace,
dataFlowInfo: DataFlowInfo dataFlowInfo: DataFlowInfo,
inferenceSession: InferenceSession?
) { ) {
if (functionDescriptor.returnType != null) return if (functionDescriptor.returnType != null) return
assert(function.typeReference == null) { assert(function.typeReference == null) {
@@ -153,7 +160,9 @@ class FunctionDescriptorResolver(
function.hasBlockBody() -> function.hasBlockBody() ->
builtIns.unitType builtIns.unitType
function.hasBody() -> function.hasBody() ->
descriptorResolver.inferReturnTypeFromExpressionBody(trace, scope, dataFlowInfo, function, functionDescriptor) descriptorResolver.inferReturnTypeFromExpressionBody(
trace, scope, dataFlowInfo, function, functionDescriptor, inferenceSession
)
else -> else ->
ErrorUtils.createErrorType("No type, no body") ErrorUtils.createErrorType("No type, no body")
} }
@@ -167,7 +176,8 @@ class FunctionDescriptorResolver(
functionDescriptor: SimpleFunctionDescriptorImpl, functionDescriptor: SimpleFunctionDescriptorImpl,
trace: BindingTrace, trace: BindingTrace,
expectedFunctionType: KotlinType, expectedFunctionType: KotlinType,
dataFlowInfo: DataFlowInfo dataFlowInfo: DataFlowInfo,
inferenceSession: InferenceSession?
) { ) {
val headerScope = LexicalWritableScope( val headerScope = LexicalWritableScope(
scope, functionDescriptor, true, scope, functionDescriptor, true,
@@ -188,7 +198,7 @@ class FunctionDescriptorResolver(
val valueParameterDescriptors = val valueParameterDescriptors =
createValueParameterDescriptors(function, functionDescriptor, headerScope, trace, expectedFunctionType) createValueParameterDescriptors(function, functionDescriptor, headerScope, trace, expectedFunctionType, inferenceSession)
headerScope.freeze() headerScope.freeze()
@@ -200,7 +210,7 @@ class FunctionDescriptorResolver(
trace.bindingContext, container trace.bindingContext, container
) )
val contractProvider = getContractProvider(functionDescriptor, trace, scope, dataFlowInfo, function) val contractProvider = getContractProvider(functionDescriptor, trace, scope, dataFlowInfo, function, inferenceSession)
val userData = mutableMapOf<CallableDescriptor.UserDataKey<*>, Any>().apply { val userData = mutableMapOf<CallableDescriptor.UserDataKey<*>, Any>().apply {
if (contractProvider != null) { if (contractProvider != null) {
put(ContractProviderKey, contractProvider) put(ContractProviderKey, contractProvider)
@@ -250,7 +260,8 @@ class FunctionDescriptorResolver(
trace: BindingTrace, trace: BindingTrace,
scope: LexicalScope, scope: LexicalScope,
dataFlowInfo: DataFlowInfo, dataFlowInfo: DataFlowInfo,
function: KtFunction function: KtFunction,
inferenceSession: InferenceSession?
): LazyContractProvider? { ): LazyContractProvider? {
if (function !is KtNamedFunction) return null if (function !is KtNamedFunction) return null
@@ -261,7 +272,7 @@ class FunctionDescriptorResolver(
return LazyContractProvider(storageManager) { return LazyContractProvider(storageManager) {
AstLoadingFilter.forceAllowTreeLoading(function.containingFile, ThrowableComputable { AstLoadingFilter.forceAllowTreeLoading(function.containingFile, ThrowableComputable {
expressionTypingServices.getBodyExpressionType(trace, scope, dataFlowInfo, function, functionDescriptor) expressionTypingServices.getBodyExpressionType(trace, scope, dataFlowInfo, function, functionDescriptor, inferenceSession)
}) })
} }
} }
@@ -271,7 +282,8 @@ class FunctionDescriptorResolver(
functionDescriptor: SimpleFunctionDescriptorImpl, functionDescriptor: SimpleFunctionDescriptorImpl,
innerScope: LexicalWritableScope, innerScope: LexicalWritableScope,
trace: BindingTrace, trace: BindingTrace,
expectedFunctionType: KotlinType expectedFunctionType: KotlinType,
inferenceSession: InferenceSession?
): List<ValueParameterDescriptor> { ): List<ValueParameterDescriptor> {
val expectedValueParameters = expectedFunctionType.getValueParameters(functionDescriptor) val expectedValueParameters = expectedFunctionType.getValueParameters(functionDescriptor)
val expectedParameterTypes = expectedValueParameters?.map { it.type.removeParameterNameAnnotation() } val expectedParameterTypes = expectedValueParameters?.map { it.type.removeParameterNameAnnotation() }
@@ -300,7 +312,8 @@ class FunctionDescriptorResolver(
innerScope, innerScope,
function.valueParameters, function.valueParameters,
trace, trace,
expectedParameterTypes expectedParameterTypes,
inferenceSession
) )
} }
@@ -324,7 +337,8 @@ class FunctionDescriptorResolver(
classDescriptor: ClassDescriptor, classDescriptor: ClassDescriptor,
classElement: KtPureClassOrObject, classElement: KtPureClassOrObject,
trace: BindingTrace, trace: BindingTrace,
languageVersionSettings: LanguageVersionSettings languageVersionSettings: LanguageVersionSettings,
inferenceSession: InferenceSession?
): ClassConstructorDescriptorImpl? { ): ClassConstructorDescriptorImpl? {
if (classDescriptor.kind == ClassKind.ENUM_ENTRY || !classElement.hasPrimaryConstructor()) return null if (classDescriptor.kind == ClassKind.ENUM_ENTRY || !classElement.hasPrimaryConstructor()) return null
return createConstructorDescriptor( return createConstructorDescriptor(
@@ -335,7 +349,8 @@ class FunctionDescriptorResolver(
classElement.primaryConstructor ?: classElement, classElement.primaryConstructor ?: classElement,
classElement.primaryConstructorParameters, classElement.primaryConstructorParameters,
trace, trace,
languageVersionSettings languageVersionSettings,
inferenceSession
) )
} }
@@ -344,7 +359,8 @@ class FunctionDescriptorResolver(
classDescriptor: ClassDescriptor, classDescriptor: ClassDescriptor,
constructor: KtSecondaryConstructor, constructor: KtSecondaryConstructor,
trace: BindingTrace, trace: BindingTrace,
languageVersionSettings: LanguageVersionSettings languageVersionSettings: LanguageVersionSettings,
inferenceSession: InferenceSession?
): ClassConstructorDescriptorImpl { ): ClassConstructorDescriptorImpl {
return createConstructorDescriptor( return createConstructorDescriptor(
scope, scope,
@@ -354,7 +370,8 @@ class FunctionDescriptorResolver(
constructor, constructor,
constructor.valueParameters, constructor.valueParameters,
trace, trace,
languageVersionSettings languageVersionSettings,
inferenceSession
) )
} }
@@ -366,7 +383,8 @@ class FunctionDescriptorResolver(
declarationToTrace: KtPureElement, declarationToTrace: KtPureElement,
valueParameters: List<KtParameter>, valueParameters: List<KtParameter>,
trace: BindingTrace, trace: BindingTrace,
languageVersionSettings: LanguageVersionSettings languageVersionSettings: LanguageVersionSettings,
inferenceSession: InferenceSession?
): ClassConstructorDescriptorImpl { ): ClassConstructorDescriptorImpl {
val constructorDescriptor = ClassConstructorDescriptorImpl.create( val constructorDescriptor = ClassConstructorDescriptorImpl.create(
classDescriptor, classDescriptor,
@@ -375,8 +393,7 @@ class FunctionDescriptorResolver(
declarationToTrace.toSourceElement() declarationToTrace.toSourceElement()
) )
constructorDescriptor.isExpect = classDescriptor.isExpect constructorDescriptor.isExpect = classDescriptor.isExpect
constructorDescriptor.isActual = constructorDescriptor.isActual = modifierList?.hasActualModifier() == true ||
modifierList?.hasActualModifier() == true ||
// We don't require 'actual' for constructors of actual annotations // We don't require 'actual' for constructors of actual annotations
classDescriptor.kind == ClassKind.ANNOTATION_CLASS && classDescriptor.isActual classDescriptor.kind == ClassKind.ANNOTATION_CLASS && classDescriptor.isActual
if (declarationToTrace is PsiElement) if (declarationToTrace is PsiElement)
@@ -389,7 +406,9 @@ class FunctionDescriptorResolver(
LexicalScopeKind.CONSTRUCTOR_HEADER LexicalScopeKind.CONSTRUCTOR_HEADER
) )
val constructor = constructorDescriptor.initialize( val constructor = constructorDescriptor.initialize(
resolveValueParameters(constructorDescriptor, parameterScope, valueParameters, trace, null), resolveValueParameters(
constructorDescriptor, parameterScope, valueParameters, trace, null, inferenceSession
),
resolveVisibilityFromModifiers( resolveVisibilityFromModifiers(
modifierList, modifierList,
DescriptorUtils.getDefaultConstructorVisibility(classDescriptor, languageVersionSettings.supportsFeature(LanguageFeature.AllowSealedInheritorsInDifferentFilesOfSamePackage)) DescriptorUtils.getDefaultConstructorVisibility(classDescriptor, languageVersionSettings.supportsFeature(LanguageFeature.AllowSealedInheritorsInDifferentFilesOfSamePackage))
@@ -407,7 +426,8 @@ class FunctionDescriptorResolver(
parameterScope: LexicalWritableScope, parameterScope: LexicalWritableScope,
valueParameters: List<KtParameter>, valueParameters: List<KtParameter>,
trace: BindingTrace, trace: BindingTrace,
expectedParameterTypes: List<KotlinType>? expectedParameterTypes: List<KotlinType>?,
inferenceSession: InferenceSession?
): List<ValueParameterDescriptor> { ): List<ValueParameterDescriptor> {
val result = ArrayList<ValueParameterDescriptor>() val result = ArrayList<ValueParameterDescriptor>()
@@ -451,7 +471,7 @@ class FunctionDescriptorResolver(
} }
val valueParameterDescriptor = descriptorResolver.resolveValueParameterDescriptor( val valueParameterDescriptor = descriptorResolver.resolveValueParameterDescriptor(
parameterScope, functionDescriptor, valueParameter, i, type, trace, Annotations.EMPTY parameterScope, functionDescriptor, valueParameter, i, type, trace, Annotations.EMPTY, inferenceSession
) )
// Do not report NAME_SHADOWING for lambda destructured parameters as they may be not fully resolved at this time // Do not report NAME_SHADOWING for lambda destructured parameters as they may be not fully resolved at this time
@@ -153,7 +153,7 @@ class VariableTypeAndInitializerResolver(
) )
val getterReturnType = delegatedPropertyResolver.getGetValueMethodReturnType( val getterReturnType = delegatedPropertyResolver.getGetValueMethodReturnType(
variableDescriptor, delegateExpression, type, trace, scopeForInitializer, dataFlowInfo variableDescriptor, delegateExpression, type, trace, scopeForInitializer, dataFlowInfo, inferenceSession
) )
val delegatedType = getterReturnType?.let { approximateType(it, local) } val delegatedType = getterReturnType?.let { approximateType(it, local) }
@@ -297,12 +297,14 @@ public class CallResolver {
@NotNull Call call, @NotNull Call call,
@NotNull KotlinType expectedType, @NotNull KotlinType expectedType,
@NotNull DataFlowInfo dataFlowInfo, @NotNull DataFlowInfo dataFlowInfo,
boolean isAnnotationContext boolean isAnnotationContext,
@Nullable InferenceSession inferenceSession
) { ) {
return resolveFunctionCall( return resolveFunctionCall(
BasicCallResolutionContext.create( BasicCallResolutionContext.create(
trace, scope, call, expectedType, dataFlowInfo, ContextDependency.INDEPENDENT, CheckArgumentTypesMode.CHECK_VALUE_ARGUMENTS, trace, scope, call, expectedType, dataFlowInfo, ContextDependency.INDEPENDENT, CheckArgumentTypesMode.CHECK_VALUE_ARGUMENTS,
isAnnotationContext, languageVersionSettings, dataFlowValueFactory, InferenceSession.Companion.getDefault() isAnnotationContext, languageVersionSettings, dataFlowValueFactory,
inferenceSession != null ? inferenceSession : InferenceSession.Companion.getDefault()
) )
); );
} }
@@ -423,7 +425,8 @@ public class CallResolver {
public OverloadResolutionResults<ConstructorDescriptor> resolveConstructorDelegationCall( public OverloadResolutionResults<ConstructorDescriptor> resolveConstructorDelegationCall(
@NotNull BindingTrace trace, @NotNull LexicalScope scope, @NotNull DataFlowInfo dataFlowInfo, @NotNull BindingTrace trace, @NotNull LexicalScope scope, @NotNull DataFlowInfo dataFlowInfo,
@NotNull ClassConstructorDescriptor constructorDescriptor, @NotNull ClassConstructorDescriptor constructorDescriptor,
@NotNull KtConstructorDelegationCall call @NotNull KtConstructorDelegationCall call,
@Nullable InferenceSession inferenceSession
) { ) {
// Method returns `null` when there is nothing to resolve in trivial cases like `null` call expression or // Method returns `null` when there is nothing to resolve in trivial cases like `null` call expression or
// when super call should be conventional enum constructor and super call should be empty // when super call should be conventional enum constructor and super call should be empty
@@ -436,7 +439,7 @@ public class CallResolver {
false, false,
languageVersionSettings, languageVersionSettings,
dataFlowValueFactory, dataFlowValueFactory,
InferenceSession.Companion.getDefault()); inferenceSession != null ? inferenceSession : InferenceSession.Companion.getDefault());
KtConstructorDelegationReferenceExpression calleeExpression = call.getCalleeExpression(); KtConstructorDelegationReferenceExpression calleeExpression = call.getCalleeExpression();
@@ -66,7 +66,7 @@ class BuilderInferenceSession(
private val commonCalls = arrayListOf<PSICompletedCallInfo>() private val commonCalls = arrayListOf<PSICompletedCallInfo>()
// Simple calls are calls which might not have gone through type inference, but may contain unsubstituted postponed variables inside their types. // These calls come from the old type inference
private val oldCallableReferenceCalls = arrayListOf<KtExpression>() private val oldCallableReferenceCalls = arrayListOf<KtExpression>()
private var hasInapplicableCall = false private var hasInapplicableCall = false
@@ -21,6 +21,7 @@ import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.descriptors.SupertypeLoopChecker import org.jetbrains.kotlin.descriptors.SupertypeLoopChecker
import org.jetbrains.kotlin.incremental.components.LookupTracker import org.jetbrains.kotlin.incremental.components.LookupTracker
import org.jetbrains.kotlin.resolve.* import org.jetbrains.kotlin.resolve.*
import org.jetbrains.kotlin.resolve.calls.components.InferenceSession
import org.jetbrains.kotlin.resolve.extensions.SyntheticResolveExtension import org.jetbrains.kotlin.resolve.extensions.SyntheticResolveExtension
import org.jetbrains.kotlin.resolve.lazy.declarations.DeclarationProviderFactory import org.jetbrains.kotlin.resolve.lazy.declarations.DeclarationProviderFactory
import org.jetbrains.kotlin.resolve.sam.SamConversionResolver import org.jetbrains.kotlin.resolve.sam.SamConversionResolver
@@ -30,6 +31,7 @@ import org.jetbrains.kotlin.types.checker.NewKotlinTypeChecker
interface LazyClassContext { interface LazyClassContext {
val declarationScopeProvider: DeclarationScopeProvider val declarationScopeProvider: DeclarationScopeProvider
val inferenceSession: InferenceSession?
val storageManager: StorageManager val storageManager: StorageManager
val trace: BindingTrace val trace: BindingTrace
@@ -35,6 +35,7 @@ import org.jetbrains.kotlin.name.FqName;
import org.jetbrains.kotlin.name.Name; import org.jetbrains.kotlin.name.Name;
import org.jetbrains.kotlin.psi.*; import org.jetbrains.kotlin.psi.*;
import org.jetbrains.kotlin.resolve.*; import org.jetbrains.kotlin.resolve.*;
import org.jetbrains.kotlin.resolve.calls.components.InferenceSession;
import org.jetbrains.kotlin.resolve.checkers.PlatformDiagnosticSuppressor; import org.jetbrains.kotlin.resolve.checkers.PlatformDiagnosticSuppressor;
import org.jetbrains.kotlin.resolve.extensions.SyntheticResolveExtension; import org.jetbrains.kotlin.resolve.extensions.SyntheticResolveExtension;
import org.jetbrains.kotlin.resolve.lazy.declarations.DeclarationProviderFactory; import org.jetbrains.kotlin.resolve.lazy.declarations.DeclarationProviderFactory;
@@ -525,4 +526,11 @@ public class ResolveSession implements KotlinCodeAnalyzer, LazyClassContext {
public SealedClassInheritorsProvider getSealedClassInheritorsProvider() { public SealedClassInheritorsProvider getSealedClassInheritorsProvider() {
return sealedClassInheritorsProvider; return sealedClassInheritorsProvider;
} }
// TODO: get inference session, otherwise, for instance, builder inference session is lost here
@Nullable
@Override
public InferenceSession getInferenceSession() {
return null;
}
} }
@@ -117,7 +117,8 @@ protected constructor(
getScopeForMemberDeclarationResolution(functionDeclaration), getScopeForMemberDeclarationResolution(functionDeclaration),
functionDeclaration, functionDeclaration,
trace, trace,
c.declarationScopeProvider.getOuterDataFlowInfoForDeclaration(functionDeclaration) c.declarationScopeProvider.getOuterDataFlowInfoForDeclaration(functionDeclaration),
c.inferenceSession
) )
) )
} }
@@ -505,7 +505,8 @@ open class LazyClassMemberScope(
if (DescriptorUtils.canHaveDeclaredConstructors(thisDescriptor) || hasPrimaryConstructor) { if (DescriptorUtils.canHaveDeclaredConstructors(thisDescriptor) || hasPrimaryConstructor) {
val constructor = c.functionDescriptorResolver.resolvePrimaryConstructorDescriptor( val constructor = c.functionDescriptorResolver.resolvePrimaryConstructorDescriptor(
thisDescriptor.scopeForConstructorHeaderResolution, thisDescriptor, classOrObject, trace, c.languageVersionSettings thisDescriptor.scopeForConstructorHeaderResolution, thisDescriptor,
classOrObject, trace, c.languageVersionSettings, c.inferenceSession
) )
constructor ?: return null constructor ?: return null
setDeferredReturnType(constructor) setDeferredReturnType(constructor)
@@ -522,7 +523,8 @@ open class LazyClassMemberScope(
return classOrObject.secondaryConstructors.map { constructor -> return classOrObject.secondaryConstructors.map { constructor ->
val descriptor = c.functionDescriptorResolver.resolveSecondaryConstructorDescriptor( val descriptor = c.functionDescriptorResolver.resolveSecondaryConstructorDescriptor(
thisDescriptor.scopeForConstructorHeaderResolution, thisDescriptor, constructor, trace, c.languageVersionSettings thisDescriptor.scopeForConstructorHeaderResolution, thisDescriptor,
constructor, trace, c.languageVersionSettings, c.inferenceSession
) )
setDeferredReturnType(descriptor) setDeferredReturnType(descriptor)
descriptor descriptor
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.types.expressions;
import kotlin.jvm.functions.Function1; import kotlin.jvm.functions.Function1;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.config.LanguageVersionSettings; import org.jetbrains.kotlin.config.LanguageVersionSettings;
import org.jetbrains.kotlin.psi.KtExpression; import org.jetbrains.kotlin.psi.KtExpression;
import org.jetbrains.kotlin.resolve.BindingTrace; import org.jetbrains.kotlin.resolve.BindingTrace;
@@ -41,10 +42,12 @@ public class ExpressionTypingContext extends ResolutionContext<ExpressionTypingC
@NotNull KotlinType expectedType, @NotNull KotlinType expectedType,
@NotNull LanguageVersionSettings languageVersionSettings, @NotNull LanguageVersionSettings languageVersionSettings,
@NotNull DataFlowValueFactory dataFlowValueFactory, @NotNull DataFlowValueFactory dataFlowValueFactory,
@NotNull InferenceSession inferenceSession @Nullable InferenceSession inferenceSession
) { ) {
return newContext(trace, scope, dataFlowInfo, expectedType, ContextDependency.INDEPENDENT, StatementFilter.NONE, return newContext(
languageVersionSettings, dataFlowValueFactory, inferenceSession); trace, scope, dataFlowInfo, expectedType, ContextDependency.INDEPENDENT, StatementFilter.NONE, languageVersionSettings,
dataFlowValueFactory, inferenceSession != null ? inferenceSession : InferenceSession.Companion.getDefault()
);
} }
@NotNull @NotNull
@@ -159,7 +159,7 @@ public class ExpressionTypingServices {
trace, trace,
functionInnerScope, dataFlowInfo, expectedReturnType != null ? expectedReturnType : NO_EXPECTED_TYPE, functionInnerScope, dataFlowInfo, expectedReturnType != null ? expectedReturnType : NO_EXPECTED_TYPE,
getLanguageVersionSettings(), expressionTypingComponents.dataFlowValueFactory, getLanguageVersionSettings(), expressionTypingComponents.dataFlowValueFactory,
localContext == null ? InferenceSession.Companion.getDefault() : localContext.inferenceSession localContext != null ? localContext.inferenceSession : InferenceSession.Companion.getDefault()
); );
checkFunctionReturnType(function, context); checkFunctionReturnType(function, context);
@@ -221,7 +221,8 @@ public class ExpressionTypingServices {
@NotNull LexicalScope outerScope, @NotNull LexicalScope outerScope,
@NotNull DataFlowInfo dataFlowInfo, @NotNull DataFlowInfo dataFlowInfo,
@NotNull KtDeclarationWithBody function, @NotNull KtDeclarationWithBody function,
@NotNull FunctionDescriptor functionDescriptor @NotNull FunctionDescriptor functionDescriptor,
@Nullable InferenceSession inferenceSession
) { ) {
KtExpression bodyExpression = function.getBodyExpression(); KtExpression bodyExpression = function.getBodyExpression();
assert bodyExpression != null; assert bodyExpression != null;
@@ -230,7 +231,7 @@ public class ExpressionTypingServices {
ExpressionTypingContext context = ExpressionTypingContext.newContext( ExpressionTypingContext context = ExpressionTypingContext.newContext(
trace, functionInnerScope, dataFlowInfo, NO_EXPECTED_TYPE, getLanguageVersionSettings(), trace, functionInnerScope, dataFlowInfo, NO_EXPECTED_TYPE, getLanguageVersionSettings(),
expressionTypingComponents.dataFlowValueFactory expressionTypingComponents.dataFlowValueFactory, inferenceSession
); );
KotlinResolutionCallbacksImpl.LambdaInfo lambdaInfo = getNewInferenceLambdaInfo(context, function); KotlinResolutionCallbacksImpl.LambdaInfo lambdaInfo = getNewInferenceLambdaInfo(context, function);
@@ -77,7 +77,7 @@ internal class FunctionsTypingVisitor(facade: ExpressionTypingInternals) : Expre
val functionDescriptor: SimpleFunctionDescriptor val functionDescriptor: SimpleFunctionDescriptor
if (isDeclaration) { if (isDeclaration) {
functionDescriptor = components.functionDescriptorResolver.resolveFunctionDescriptor( functionDescriptor = components.functionDescriptorResolver.resolveFunctionDescriptor(
context.scope.ownerDescriptor, context.scope, function, context.trace, context.dataFlowInfo context.scope.ownerDescriptor, context.scope, function, context.trace, context.dataFlowInfo, context.inferenceSession
) )
assert(statementScope != null) { assert(statementScope != null) {
"statementScope must be not null for function: " + function.name + " at location " + PsiDiagnosticUtils.atLocation( "statementScope must be not null for function: " + function.name + " at location " + PsiDiagnosticUtils.atLocation(
@@ -88,7 +88,7 @@ internal class FunctionsTypingVisitor(facade: ExpressionTypingInternals) : Expre
} else { } else {
functionDescriptor = components.functionDescriptorResolver.resolveFunctionExpressionDescriptor( functionDescriptor = components.functionDescriptorResolver.resolveFunctionExpressionDescriptor(
context.scope.ownerDescriptor, context.scope, function, context.scope.ownerDescriptor, context.scope, function,
context.trace, context.dataFlowInfo, context.expectedType context.trace, context.dataFlowInfo, context.expectedType, context.inferenceSession
) )
} }
// Necessary for local functions // Necessary for local functions
@@ -105,7 +105,8 @@ internal class FunctionsTypingVisitor(facade: ExpressionTypingInternals) : Expre
} }
components.valueParameterResolver.resolveValueParameters( components.valueParameterResolver.resolveValueParameters(
function.valueParameters, functionDescriptor.valueParameters, functionInnerScope, context.dataFlowInfo, context.trace function.valueParameters, functionDescriptor.valueParameters, functionInnerScope,
context.dataFlowInfo, context.trace, context.inferenceSession
) )
components.modifiersChecker.withTrace(context.trace).checkModifiersForLocalDeclaration(function, functionDescriptor) components.modifiersChecker.withTrace(context.trace).checkModifiersForLocalDeclaration(function, functionDescriptor)
@@ -211,7 +212,7 @@ internal class FunctionsTypingVisitor(facade: ExpressionTypingInternals) : Expre
} }
components.functionDescriptorResolver.initializeFunctionDescriptorAndExplicitReturnType( components.functionDescriptorResolver.initializeFunctionDescriptorAndExplicitReturnType(
context.scope.ownerDescriptor, context.scope, functionLiteral, context.scope.ownerDescriptor, context.scope, functionLiteral,
functionDescriptor, context.trace, context.expectedType, context.dataFlowInfo functionDescriptor, context.trace, context.expectedType, context.dataFlowInfo, context.inferenceSession
) )
for (parameterDescriptor in functionDescriptor.valueParameters) { for (parameterDescriptor in functionDescriptor.valueParameters) {
ForceResolveUtil.forceResolveAllContents(parameterDescriptor.annotations) ForceResolveUtil.forceResolveAllContents(parameterDescriptor.annotations)
@@ -38,6 +38,7 @@ import org.jetbrains.kotlin.psi.KtClassOrObject
import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.psi.debugText.getDebugText import org.jetbrains.kotlin.psi.debugText.getDebugText
import org.jetbrains.kotlin.resolve.* import org.jetbrains.kotlin.resolve.*
import org.jetbrains.kotlin.resolve.calls.components.InferenceSession
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
import org.jetbrains.kotlin.resolve.extensions.SyntheticResolveExtension import org.jetbrains.kotlin.resolve.extensions.SyntheticResolveExtension
import org.jetbrains.kotlin.resolve.lazy.* import org.jetbrains.kotlin.resolve.lazy.*
@@ -158,6 +159,7 @@ class LocalClassDescriptorHolder(
classDescriptor = LazyClassDescriptor( classDescriptor = LazyClassDescriptor(
object : LazyClassContext { object : LazyClassContext {
override val declarationScopeProvider = declarationScopeProvider override val declarationScopeProvider = declarationScopeProvider
override val inferenceSession = expressionTypingContext.inferenceSession
override val storageManager = this@LocalClassDescriptorHolder.storageManager override val storageManager = this@LocalClassDescriptorHolder.storageManager
override val trace = expressionTypingContext.trace override val trace = expressionTypingContext.trace
override val moduleDescriptor = this@LocalClassDescriptorHolder.moduleDescriptor override val moduleDescriptor = this@LocalClassDescriptorHolder.moduleDescriptor
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.psi.KtParameter
import org.jetbrains.kotlin.resolve.BindingTrace import org.jetbrains.kotlin.resolve.BindingTrace
import org.jetbrains.kotlin.resolve.DescriptorResolver import org.jetbrains.kotlin.resolve.DescriptorResolver
import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.calls.components.InferenceSession
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory
import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluator import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluator
@@ -44,14 +45,15 @@ class ValueParameterResolver(
valueParameterDescriptors: List<ValueParameterDescriptor>, valueParameterDescriptors: List<ValueParameterDescriptor>,
declaringScope: LexicalScope, declaringScope: LexicalScope,
dataFlowInfo: DataFlowInfo, dataFlowInfo: DataFlowInfo,
trace: BindingTrace trace: BindingTrace,
inferenceSession: InferenceSession?
) { ) {
val scopeForDefaultValue = val scopeForDefaultValue =
LexicalScopeImpl(declaringScope, declaringScope.ownerDescriptor, false, null, LexicalScopeKind.DEFAULT_VALUE) LexicalScopeImpl(declaringScope, declaringScope.ownerDescriptor, false, null, LexicalScopeKind.DEFAULT_VALUE)
val contextForDefaultValue = ExpressionTypingContext.newContext( val contextForDefaultValue = ExpressionTypingContext.newContext(
trace, scopeForDefaultValue, dataFlowInfo, TypeUtils.NO_EXPECTED_TYPE, trace, scopeForDefaultValue, dataFlowInfo, TypeUtils.NO_EXPECTED_TYPE,
languageVersionSettings, dataFlowValueFactory languageVersionSettings, dataFlowValueFactory, inferenceSession
) )
for ((descriptor, parameter) in valueParameterDescriptors.zip(valueParameters)) { for ((descriptor, parameter) in valueParameterDescriptors.zip(valueParameters)) {
@@ -0,0 +1,54 @@
// WITH_RUNTIME
// DONT_TARGET_EXACT_BACKEND: WASM
@OptIn(ExperimentalStdlibApi::class)
fun foo1() {
buildList {
object {
fun foo() = add("")
}
}
}
@OptIn(ExperimentalStdlibApi::class)
fun foo2() {
buildList {
class A {
fun foo() = add("")
}
}
}
@OptIn(ExperimentalStdlibApi::class)
fun foo3() {
buildList {
object {
var x: Int
get() = 1
set(value) {
add(value)
}
}
}
}
@OptIn(ExperimentalStdlibApi::class)
fun foo4() {
buildList {
class A {
var x: Int
get() = 1
set(value) {
add(value)
}
}
}
}
fun box(): String {
foo1()
foo2()
foo3()
foo4()
return "OK"
}
@@ -0,0 +1,109 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER -EXPERIMENTAL_IS_NOT_ENABLED
// WITH_RUNTIME
import kotlin.experimental.ExperimentalTypeInference
@OptIn(ExperimentalTypeInference::class)
class A1<T> {
fun <BT1> builder1(@BuilderInference configure: A2<BT1>.() -> Unit) {}
}
@OptIn(ExperimentalTypeInference::class)
class A2<A2_BT1> {
fun <BT2> builder2(@BuilderInference configure: A3<A2_BT1, BT2>.() -> Unit) {}
}
@OptIn(ExperimentalTypeInference::class)
class A3<A3_BT1, A3_BT2> {
fun <BT3> builder3(@BuilderInference configure: A4<A3_BT1, A3_BT2, BT3>.() -> Unit) {}
}
class A4<A3_BT1, A3_BT2, A3_BT3> {
fun resolver(x: A3_BT3) {}
}
fun foo1(x: A1<String>) {
x.builder1<String> {
val x by lazy {
builder2<String> {
builder3 {
resolver("")
}
}
}
}
}
fun foo2(x: A1<String>) {
x.builder1<String> {
builder2<String> {
val x by lazy {
builder3 {
resolver("")
}
}
}
}
}
fun foo3(x: A1<String>) {
x.builder1<String> {
builder2<String> {
class A {
fun foo() = builder3 {
resolver("")
}
}
}
}
}
fun foo4(x: A1<String>) {
x.builder1<String> {
class A {
fun foo() = builder2<String> {
builder3 {
resolver("")
}
}
}
}
}
fun foo5(x: A1<String>) {
x.builder1<String> {
builder2<String> {
class A {
fun foo() {
builder3 {
resolver("")
}
}
}
}
}
}
fun foo6(x: A1<String>) {
x.builder1<String> {
class A {
fun foo() {
builder2<String> {
builder3 {
resolver("")
}
}
}
}
}
}
fun box(): String {
foo1(A1())
foo2(A1())
foo3(A1())
foo4(A1())
foo5(A1())
foo6(A1())
return "OK"
}
@@ -16969,6 +16969,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/inference/builderInference"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true); KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/inference/builderInference"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true);
} }
@Test
@TestMetadata("builderCallAsReturnTypeInLocalClass.kt")
public void testBuilderCallAsReturnTypeInLocalClass() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/builderCallAsReturnTypeInLocalClass.kt");
}
@Test @Test
@TestMetadata("callableReferenceAndCoercionToUnit.kt") @TestMetadata("callableReferenceAndCoercionToUnit.kt")
public void testCallableReferenceAndCoercionToUnit() throws Exception { public void testCallableReferenceAndCoercionToUnit() throws Exception {
@@ -16987,18 +16993,6 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/inference/builderInference/lackOfNullCheckOnNullableInsideBuild.kt"); runTest("compiler/testData/codegen/box/inference/builderInference/lackOfNullCheckOnNullableInsideBuild.kt");
} }
@Test
@TestMetadata("multiStepCompletionWithinThreeBuilderInferenceCalls.kt")
public void testMultiStepCompletionWithinThreeBuilderInferenceCalls() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/multiStepCompletionWithinThreeBuilderInferenceCalls.kt");
}
@Test
@TestMetadata("multiStepCompletionWithinTwoBuilderInferenceCalls.kt")
public void testMultiStepCompletionWithinTwoBuilderInferenceCalls() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/multiStepCompletionWithinTwoBuilderInferenceCalls.kt");
}
@Test @Test
@TestMetadata("propagateInferenceSessionIntoDeclarationAnalyzers.kt") @TestMetadata("propagateInferenceSessionIntoDeclarationAnalyzers.kt")
public void testPropagateInferenceSessionIntoDeclarationAnalyzers() throws Exception { public void testPropagateInferenceSessionIntoDeclarationAnalyzers() throws Exception {
@@ -17058,6 +17052,24 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
public void testSubstitutelambdaExtensionReceiverType() throws Exception { public void testSubstitutelambdaExtensionReceiverType() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/substitutelambdaExtensionReceiverType.kt"); runTest("compiler/testData/codegen/box/inference/builderInference/substitutelambdaExtensionReceiverType.kt");
} }
@Test
@TestMetadata("topDownCompletionBreakedByNonBuilderInferenceSession.kt")
public void testTopDownCompletionBreakedByNonBuilderInferenceSession() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/topDownCompletionBreakedByNonBuilderInferenceSession.kt");
}
@Test
@TestMetadata("topDownCompletionWithThreeBuilderInferenceCalls.kt")
public void testTopDownCompletionWithThreeBuilderInferenceCalls() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/topDownCompletionWithThreeBuilderInferenceCalls.kt");
}
@Test
@TestMetadata("topDownCompletionWithTwoBuilderInferenceCalls.kt")
public void testTopDownCompletionWithTwoBuilderInferenceCalls() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/topDownCompletionWithTwoBuilderInferenceCalls.kt");
}
} }
} }
@@ -16969,6 +16969,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/inference/builderInference"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/inference/builderInference"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
} }
@Test
@TestMetadata("builderCallAsReturnTypeInLocalClass.kt")
public void testBuilderCallAsReturnTypeInLocalClass() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/builderCallAsReturnTypeInLocalClass.kt");
}
@Test @Test
@TestMetadata("callableReferenceAndCoercionToUnit.kt") @TestMetadata("callableReferenceAndCoercionToUnit.kt")
public void testCallableReferenceAndCoercionToUnit() throws Exception { public void testCallableReferenceAndCoercionToUnit() throws Exception {
@@ -16987,18 +16993,6 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/inference/builderInference/lackOfNullCheckOnNullableInsideBuild.kt"); runTest("compiler/testData/codegen/box/inference/builderInference/lackOfNullCheckOnNullableInsideBuild.kt");
} }
@Test
@TestMetadata("multiStepCompletionWithinThreeBuilderInferenceCalls.kt")
public void testMultiStepCompletionWithinThreeBuilderInferenceCalls() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/multiStepCompletionWithinThreeBuilderInferenceCalls.kt");
}
@Test
@TestMetadata("multiStepCompletionWithinTwoBuilderInferenceCalls.kt")
public void testMultiStepCompletionWithinTwoBuilderInferenceCalls() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/multiStepCompletionWithinTwoBuilderInferenceCalls.kt");
}
@Test @Test
@TestMetadata("propagateInferenceSessionIntoDeclarationAnalyzers.kt") @TestMetadata("propagateInferenceSessionIntoDeclarationAnalyzers.kt")
public void testPropagateInferenceSessionIntoDeclarationAnalyzers() throws Exception { public void testPropagateInferenceSessionIntoDeclarationAnalyzers() throws Exception {
@@ -17058,6 +17052,24 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
public void testSubstitutelambdaExtensionReceiverType() throws Exception { public void testSubstitutelambdaExtensionReceiverType() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/substitutelambdaExtensionReceiverType.kt"); runTest("compiler/testData/codegen/box/inference/builderInference/substitutelambdaExtensionReceiverType.kt");
} }
@Test
@TestMetadata("topDownCompletionBreakedByNonBuilderInferenceSession.kt")
public void testTopDownCompletionBreakedByNonBuilderInferenceSession() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/topDownCompletionBreakedByNonBuilderInferenceSession.kt");
}
@Test
@TestMetadata("topDownCompletionWithThreeBuilderInferenceCalls.kt")
public void testTopDownCompletionWithThreeBuilderInferenceCalls() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/topDownCompletionWithThreeBuilderInferenceCalls.kt");
}
@Test
@TestMetadata("topDownCompletionWithTwoBuilderInferenceCalls.kt")
public void testTopDownCompletionWithTwoBuilderInferenceCalls() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/topDownCompletionWithTwoBuilderInferenceCalls.kt");
}
} }
} }
@@ -14052,6 +14052,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/inference/builderInference"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true); KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/inference/builderInference"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true);
} }
@TestMetadata("builderCallAsReturnTypeInLocalClass.kt")
public void testBuilderCallAsReturnTypeInLocalClass() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/builderCallAsReturnTypeInLocalClass.kt");
}
@TestMetadata("callableReferenceAndCoercionToUnit.kt") @TestMetadata("callableReferenceAndCoercionToUnit.kt")
public void testCallableReferenceAndCoercionToUnit() throws Exception { public void testCallableReferenceAndCoercionToUnit() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/callableReferenceAndCoercionToUnit.kt"); runTest("compiler/testData/codegen/box/inference/builderInference/callableReferenceAndCoercionToUnit.kt");
@@ -14067,16 +14072,6 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/inference/builderInference/lackOfNullCheckOnNullableInsideBuild.kt"); runTest("compiler/testData/codegen/box/inference/builderInference/lackOfNullCheckOnNullableInsideBuild.kt");
} }
@TestMetadata("multiStepCompletionWithinThreeBuilderInferenceCalls.kt")
public void testMultiStepCompletionWithinThreeBuilderInferenceCalls() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/multiStepCompletionWithinThreeBuilderInferenceCalls.kt");
}
@TestMetadata("multiStepCompletionWithinTwoBuilderInferenceCalls.kt")
public void testMultiStepCompletionWithinTwoBuilderInferenceCalls() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/multiStepCompletionWithinTwoBuilderInferenceCalls.kt");
}
@TestMetadata("propagateInferenceSessionIntoDeclarationAnalyzers.kt") @TestMetadata("propagateInferenceSessionIntoDeclarationAnalyzers.kt")
public void testPropagateInferenceSessionIntoDeclarationAnalyzers() throws Exception { public void testPropagateInferenceSessionIntoDeclarationAnalyzers() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/propagateInferenceSessionIntoDeclarationAnalyzers.kt"); runTest("compiler/testData/codegen/box/inference/builderInference/propagateInferenceSessionIntoDeclarationAnalyzers.kt");
@@ -14126,6 +14121,21 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
public void testSubstitutelambdaExtensionReceiverType() throws Exception { public void testSubstitutelambdaExtensionReceiverType() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/substitutelambdaExtensionReceiverType.kt"); runTest("compiler/testData/codegen/box/inference/builderInference/substitutelambdaExtensionReceiverType.kt");
} }
@TestMetadata("topDownCompletionBreakedByNonBuilderInferenceSession.kt")
public void testTopDownCompletionBreakedByNonBuilderInferenceSession() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/topDownCompletionBreakedByNonBuilderInferenceSession.kt");
}
@TestMetadata("topDownCompletionWithThreeBuilderInferenceCalls.kt")
public void testTopDownCompletionWithThreeBuilderInferenceCalls() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/topDownCompletionWithThreeBuilderInferenceCalls.kt");
}
@TestMetadata("topDownCompletionWithTwoBuilderInferenceCalls.kt")
public void testTopDownCompletionWithTwoBuilderInferenceCalls() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/topDownCompletionWithTwoBuilderInferenceCalls.kt");
}
} }
} }
@@ -144,7 +144,7 @@ public class DefaultModalityModifiersTest extends KotlinTestWithEnvironment {
KtNamedFunction function = (KtNamedFunction) declarations.get(0); KtNamedFunction function = (KtNamedFunction) declarations.get(0);
SimpleFunctionDescriptor functionDescriptor = SimpleFunctionDescriptor functionDescriptor =
functionDescriptorResolver.resolveFunctionDescriptor(classDescriptor, scope, function, functionDescriptorResolver.resolveFunctionDescriptor(classDescriptor, scope, function,
DummyTraces.DUMMY_TRACE, DataFlowInfoFactory.EMPTY); DummyTraces.DUMMY_TRACE, DataFlowInfoFactory.EMPTY, null);
assertEquals(expectedFunctionModality, functionDescriptor.getModality()); assertEquals(expectedFunctionModality, functionDescriptor.getModality());
} }
@@ -171,7 +171,7 @@ public class KotlinOverloadTest extends KotlinTestWithEnvironment {
KtNamedFunction function = KtPsiFactoryKt.KtPsiFactory(getProject()).createFunction(funDecl); KtNamedFunction function = KtPsiFactoryKt.KtPsiFactory(getProject()).createFunction(funDecl);
LexicalScope scope = TypeTestUtilsKt.builtInPackageAsLexicalScope(module); LexicalScope scope = TypeTestUtilsKt.builtInPackageAsLexicalScope(module);
return functionDescriptorResolver.resolveFunctionDescriptor( return functionDescriptorResolver.resolveFunctionDescriptor(
module, scope, function, DummyTraces.DUMMY_TRACE, DataFlowInfoFactory.EMPTY module, scope, function, DummyTraces.DUMMY_TRACE, DataFlowInfoFactory.EMPTY, null
); );
} }
} }
@@ -172,7 +172,7 @@ public class KotlinOverridingTest extends KotlinTestWithEnvironment {
KtNamedFunction function = KtPsiFactoryKt.KtPsiFactory(getProject()).createFunction(funDecl); KtNamedFunction function = KtPsiFactoryKt.KtPsiFactory(getProject()).createFunction(funDecl);
LexicalScope scope = TypeTestUtilsKt.builtInPackageAsLexicalScope(module); LexicalScope scope = TypeTestUtilsKt.builtInPackageAsLexicalScope(module);
return functionDescriptorResolver.resolveFunctionDescriptor( return functionDescriptorResolver.resolveFunctionDescriptor(
module, scope, function, DummyTraces.DUMMY_TRACE, DataFlowInfoFactory.EMPTY module, scope, function, DummyTraces.DUMMY_TRACE, DataFlowInfoFactory.EMPTY, null
); );
} }
} }
@@ -601,7 +601,8 @@ class ResolveElementCache(
descriptor, descriptor,
descriptor.unsubstitutedPrimaryConstructor, descriptor.unsubstitutedPrimaryConstructor,
descriptor.scopeForConstructorHeaderResolution, descriptor.scopeForConstructorHeaderResolution,
descriptor.scopeForMemberDeclarationResolution descriptor.scopeForMemberDeclarationResolution,
resolveSession.inferenceSession
) )
return trace return trace
@@ -725,7 +726,8 @@ class ResolveElementCache(
trace, trace,
primaryConstructor, primaryConstructor,
constructorDescriptor, constructorDescriptor,
scope scope,
resolveSession.inferenceSession
) )
forceResolveAnnotationsInside(primaryConstructor) forceResolveAnnotationsInside(primaryConstructor)
@@ -755,7 +757,9 @@ class ResolveElementCache(
val classOrObjectDescriptor = resolveSession.resolveToDescriptor(anonymousInitializer.containingDeclaration) as LazyClassDescriptor val classOrObjectDescriptor = resolveSession.resolveToDescriptor(anonymousInitializer.containingDeclaration) as LazyClassDescriptor
val bodyResolver = createBodyResolver(resolveSession, trace, file, statementFilter) val bodyResolver = createBodyResolver(resolveSession, trace, file, statementFilter)
bodyResolver.resolveAnonymousInitializer(DataFlowInfo.EMPTY, anonymousInitializer, classOrObjectDescriptor) bodyResolver.resolveAnonymousInitializer(
DataFlowInfo.EMPTY, anonymousInitializer, classOrObjectDescriptor, resolveSession.inferenceSession
)
forceResolveAnnotationsInside(anonymousInitializer) forceResolveAnnotationsInside(anonymousInitializer)
@@ -128,7 +128,8 @@ class RedundantSamConstructorInspection : AbstractKotlinInspection() {
val qualifiedExpression = parentCall.getQualifiedExpressionForSelectorOrThis() val qualifiedExpression = parentCall.getQualifiedExpressionForSelectorOrThis()
val expectedType = context[BindingContext.EXPECTED_EXPRESSION_TYPE, qualifiedExpression] ?: TypeUtils.NO_EXPECTED_TYPE val expectedType = context[BindingContext.EXPECTED_EXPRESSION_TYPE, qualifiedExpression] ?: TypeUtils.NO_EXPECTED_TYPE
val resolutionResults = callResolver.resolveFunctionCall(BindingTraceContext(), scope, newCall, expectedType, dataFlow, false) val resolutionResults =
callResolver.resolveFunctionCall(BindingTraceContext(), scope, newCall, expectedType, dataFlow, false, null)
if (!resolutionResults.isSuccess) return false if (!resolutionResults.isSuccess) return false
@@ -12341,6 +12341,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/inference/builderInference"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR_ES6, true); KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/inference/builderInference"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR_ES6, true);
} }
@TestMetadata("builderCallAsReturnTypeInLocalClass.kt")
public void testBuilderCallAsReturnTypeInLocalClass() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/builderCallAsReturnTypeInLocalClass.kt");
}
@TestMetadata("callableReferenceAndCoercionToUnit.kt") @TestMetadata("callableReferenceAndCoercionToUnit.kt")
public void testCallableReferenceAndCoercionToUnit() throws Exception { public void testCallableReferenceAndCoercionToUnit() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/callableReferenceAndCoercionToUnit.kt"); runTest("compiler/testData/codegen/box/inference/builderInference/callableReferenceAndCoercionToUnit.kt");
@@ -12356,16 +12361,6 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
runTest("compiler/testData/codegen/box/inference/builderInference/lackOfNullCheckOnNullableInsideBuild.kt"); runTest("compiler/testData/codegen/box/inference/builderInference/lackOfNullCheckOnNullableInsideBuild.kt");
} }
@TestMetadata("multiStepCompletionWithinThreeBuilderInferenceCalls.kt")
public void testMultiStepCompletionWithinThreeBuilderInferenceCalls() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/multiStepCompletionWithinThreeBuilderInferenceCalls.kt");
}
@TestMetadata("multiStepCompletionWithinTwoBuilderInferenceCalls.kt")
public void testMultiStepCompletionWithinTwoBuilderInferenceCalls() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/multiStepCompletionWithinTwoBuilderInferenceCalls.kt");
}
@TestMetadata("propagateInferenceSessionIntoDeclarationAnalyzers.kt") @TestMetadata("propagateInferenceSessionIntoDeclarationAnalyzers.kt")
public void testPropagateInferenceSessionIntoDeclarationAnalyzers() throws Exception { public void testPropagateInferenceSessionIntoDeclarationAnalyzers() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/propagateInferenceSessionIntoDeclarationAnalyzers.kt"); runTest("compiler/testData/codegen/box/inference/builderInference/propagateInferenceSessionIntoDeclarationAnalyzers.kt");
@@ -12410,6 +12405,21 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
public void testSubstitutelambdaExtensionReceiverType() throws Exception { public void testSubstitutelambdaExtensionReceiverType() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/substitutelambdaExtensionReceiverType.kt"); runTest("compiler/testData/codegen/box/inference/builderInference/substitutelambdaExtensionReceiverType.kt");
} }
@TestMetadata("topDownCompletionBreakedByNonBuilderInferenceSession.kt")
public void testTopDownCompletionBreakedByNonBuilderInferenceSession() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/topDownCompletionBreakedByNonBuilderInferenceSession.kt");
}
@TestMetadata("topDownCompletionWithThreeBuilderInferenceCalls.kt")
public void testTopDownCompletionWithThreeBuilderInferenceCalls() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/topDownCompletionWithThreeBuilderInferenceCalls.kt");
}
@TestMetadata("topDownCompletionWithTwoBuilderInferenceCalls.kt")
public void testTopDownCompletionWithTwoBuilderInferenceCalls() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/topDownCompletionWithTwoBuilderInferenceCalls.kt");
}
} }
} }
@@ -11762,6 +11762,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/inference/builderInference"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR, true); KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/inference/builderInference"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR, true);
} }
@TestMetadata("builderCallAsReturnTypeInLocalClass.kt")
public void testBuilderCallAsReturnTypeInLocalClass() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/builderCallAsReturnTypeInLocalClass.kt");
}
@TestMetadata("callableReferenceAndCoercionToUnit.kt") @TestMetadata("callableReferenceAndCoercionToUnit.kt")
public void testCallableReferenceAndCoercionToUnit() throws Exception { public void testCallableReferenceAndCoercionToUnit() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/callableReferenceAndCoercionToUnit.kt"); runTest("compiler/testData/codegen/box/inference/builderInference/callableReferenceAndCoercionToUnit.kt");
@@ -11777,16 +11782,6 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/inference/builderInference/lackOfNullCheckOnNullableInsideBuild.kt"); runTest("compiler/testData/codegen/box/inference/builderInference/lackOfNullCheckOnNullableInsideBuild.kt");
} }
@TestMetadata("multiStepCompletionWithinThreeBuilderInferenceCalls.kt")
public void testMultiStepCompletionWithinThreeBuilderInferenceCalls() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/multiStepCompletionWithinThreeBuilderInferenceCalls.kt");
}
@TestMetadata("multiStepCompletionWithinTwoBuilderInferenceCalls.kt")
public void testMultiStepCompletionWithinTwoBuilderInferenceCalls() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/multiStepCompletionWithinTwoBuilderInferenceCalls.kt");
}
@TestMetadata("propagateInferenceSessionIntoDeclarationAnalyzers.kt") @TestMetadata("propagateInferenceSessionIntoDeclarationAnalyzers.kt")
public void testPropagateInferenceSessionIntoDeclarationAnalyzers() throws Exception { public void testPropagateInferenceSessionIntoDeclarationAnalyzers() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/propagateInferenceSessionIntoDeclarationAnalyzers.kt"); runTest("compiler/testData/codegen/box/inference/builderInference/propagateInferenceSessionIntoDeclarationAnalyzers.kt");
@@ -11831,6 +11826,21 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
public void testSubstitutelambdaExtensionReceiverType() throws Exception { public void testSubstitutelambdaExtensionReceiverType() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/substitutelambdaExtensionReceiverType.kt"); runTest("compiler/testData/codegen/box/inference/builderInference/substitutelambdaExtensionReceiverType.kt");
} }
@TestMetadata("topDownCompletionBreakedByNonBuilderInferenceSession.kt")
public void testTopDownCompletionBreakedByNonBuilderInferenceSession() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/topDownCompletionBreakedByNonBuilderInferenceSession.kt");
}
@TestMetadata("topDownCompletionWithThreeBuilderInferenceCalls.kt")
public void testTopDownCompletionWithThreeBuilderInferenceCalls() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/topDownCompletionWithThreeBuilderInferenceCalls.kt");
}
@TestMetadata("topDownCompletionWithTwoBuilderInferenceCalls.kt")
public void testTopDownCompletionWithTwoBuilderInferenceCalls() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/topDownCompletionWithTwoBuilderInferenceCalls.kt");
}
} }
} }
@@ -11827,6 +11827,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/inference/builderInference"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS, true); KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/inference/builderInference"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS, true);
} }
@TestMetadata("builderCallAsReturnTypeInLocalClass.kt")
public void testBuilderCallAsReturnTypeInLocalClass() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/builderCallAsReturnTypeInLocalClass.kt");
}
@TestMetadata("callableReferenceAndCoercionToUnit.kt") @TestMetadata("callableReferenceAndCoercionToUnit.kt")
public void testCallableReferenceAndCoercionToUnit() throws Exception { public void testCallableReferenceAndCoercionToUnit() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/callableReferenceAndCoercionToUnit.kt"); runTest("compiler/testData/codegen/box/inference/builderInference/callableReferenceAndCoercionToUnit.kt");
@@ -11842,16 +11847,6 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/inference/builderInference/lackOfNullCheckOnNullableInsideBuild.kt"); runTest("compiler/testData/codegen/box/inference/builderInference/lackOfNullCheckOnNullableInsideBuild.kt");
} }
@TestMetadata("multiStepCompletionWithinThreeBuilderInferenceCalls.kt")
public void testMultiStepCompletionWithinThreeBuilderInferenceCalls() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/multiStepCompletionWithinThreeBuilderInferenceCalls.kt");
}
@TestMetadata("multiStepCompletionWithinTwoBuilderInferenceCalls.kt")
public void testMultiStepCompletionWithinTwoBuilderInferenceCalls() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/multiStepCompletionWithinTwoBuilderInferenceCalls.kt");
}
@TestMetadata("propagateInferenceSessionIntoDeclarationAnalyzers.kt") @TestMetadata("propagateInferenceSessionIntoDeclarationAnalyzers.kt")
public void testPropagateInferenceSessionIntoDeclarationAnalyzers() throws Exception { public void testPropagateInferenceSessionIntoDeclarationAnalyzers() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/propagateInferenceSessionIntoDeclarationAnalyzers.kt"); runTest("compiler/testData/codegen/box/inference/builderInference/propagateInferenceSessionIntoDeclarationAnalyzers.kt");
@@ -11896,6 +11891,21 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
public void testSubstitutelambdaExtensionReceiverType() throws Exception { public void testSubstitutelambdaExtensionReceiverType() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/substitutelambdaExtensionReceiverType.kt"); runTest("compiler/testData/codegen/box/inference/builderInference/substitutelambdaExtensionReceiverType.kt");
} }
@TestMetadata("topDownCompletionBreakedByNonBuilderInferenceSession.kt")
public void testTopDownCompletionBreakedByNonBuilderInferenceSession() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/topDownCompletionBreakedByNonBuilderInferenceSession.kt");
}
@TestMetadata("topDownCompletionWithThreeBuilderInferenceCalls.kt")
public void testTopDownCompletionWithThreeBuilderInferenceCalls() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/topDownCompletionWithThreeBuilderInferenceCalls.kt");
}
@TestMetadata("topDownCompletionWithTwoBuilderInferenceCalls.kt")
public void testTopDownCompletionWithTwoBuilderInferenceCalls() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/topDownCompletionWithTwoBuilderInferenceCalls.kt");
}
} }
} }
@@ -6288,16 +6288,6 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
runTest("compiler/testData/codegen/box/inference/builderInference/lackOfNullCheckOnNullableInsideBuild.kt"); runTest("compiler/testData/codegen/box/inference/builderInference/lackOfNullCheckOnNullableInsideBuild.kt");
} }
@TestMetadata("multiStepCompletionWithinThreeBuilderInferenceCalls.kt")
public void testMultiStepCompletionWithinThreeBuilderInferenceCalls() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/multiStepCompletionWithinThreeBuilderInferenceCalls.kt");
}
@TestMetadata("multiStepCompletionWithinTwoBuilderInferenceCalls.kt")
public void testMultiStepCompletionWithinTwoBuilderInferenceCalls() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/multiStepCompletionWithinTwoBuilderInferenceCalls.kt");
}
@TestMetadata("propagateInferenceSessionIntoDeclarationAnalyzers.kt") @TestMetadata("propagateInferenceSessionIntoDeclarationAnalyzers.kt")
public void testPropagateInferenceSessionIntoDeclarationAnalyzers() throws Exception { public void testPropagateInferenceSessionIntoDeclarationAnalyzers() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/propagateInferenceSessionIntoDeclarationAnalyzers.kt"); runTest("compiler/testData/codegen/box/inference/builderInference/propagateInferenceSessionIntoDeclarationAnalyzers.kt");
@@ -6307,6 +6297,21 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
public void testSubstituteStubTypeIntolambdaParameterDescriptor() throws Exception { public void testSubstituteStubTypeIntolambdaParameterDescriptor() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/substituteStubTypeIntolambdaParameterDescriptor.kt"); runTest("compiler/testData/codegen/box/inference/builderInference/substituteStubTypeIntolambdaParameterDescriptor.kt");
} }
@TestMetadata("topDownCompletionBreakedByNonBuilderInferenceSession.kt")
public void testTopDownCompletionBreakedByNonBuilderInferenceSession() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/topDownCompletionBreakedByNonBuilderInferenceSession.kt");
}
@TestMetadata("topDownCompletionWithThreeBuilderInferenceCalls.kt")
public void testTopDownCompletionWithThreeBuilderInferenceCalls() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/topDownCompletionWithThreeBuilderInferenceCalls.kt");
}
@TestMetadata("topDownCompletionWithTwoBuilderInferenceCalls.kt")
public void testTopDownCompletionWithTwoBuilderInferenceCalls() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/topDownCompletionWithTwoBuilderInferenceCalls.kt");
}
} }
} }