diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CompletionModeCalculator.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CompletionModeCalculator.kt index 373901a400b..9c28b04400c 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CompletionModeCalculator.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CompletionModeCalculator.kt @@ -7,6 +7,7 @@ package org.jetbrains.kotlin.resolve.calls.components import org.jetbrains.kotlin.resolve.calls.inference.components.KotlinConstraintSystemCompleter import org.jetbrains.kotlin.resolve.calls.inference.components.KotlinConstraintSystemCompleter.ConstraintSystemCompletionMode +import org.jetbrains.kotlin.resolve.calls.inference.components.TrivialConstraintTypeInferenceOracle import org.jetbrains.kotlin.resolve.calls.inference.model.Constraint import org.jetbrains.kotlin.resolve.calls.inference.model.VariableWithConstraints import org.jetbrains.kotlin.resolve.calls.model.KotlinResolutionCandidate @@ -23,7 +24,8 @@ class CompletionModeCalculator { fun computeCompletionMode( candidate: KotlinResolutionCandidate, expectedType: UnwrappedType?, - returnType: UnwrappedType? + returnType: UnwrappedType?, + trivialConstraintTypeInferenceOracle: TrivialConstraintTypeInferenceOracle ): ConstraintSystemCompletionMode = with(candidate) { val csCompleterContext = getSystem().asConstraintSystemCompleterContext() @@ -37,13 +39,14 @@ class CompletionModeCalculator { if (csBuilder.isProperType(returnType)) return ConstraintSystemCompletionMode.FULL // For nested call with variables in return type check possibility of full completion - return CalculatorForNestedCall(returnType, csCompleterContext).computeCompletionMode() + return CalculatorForNestedCall(returnType, csCompleterContext, trivialConstraintTypeInferenceOracle).computeCompletionMode() } } private class CalculatorForNestedCall( private val returnType: UnwrappedType?, - private val csCompleterContext: CsCompleterContext + private val csCompleterContext: CsCompleterContext, + private val trivialConstraintTypeInferenceOracle: TrivialConstraintTypeInferenceOracle ) { private enum class FixationDirection { TO_SUBTYPE, EQUALITY @@ -166,6 +169,7 @@ class CompletionModeCalculator { constraint.hasRequiredKind(direction) && !constraint.type.typeConstructor().isIntegerLiteralTypeConstructor() && isProperType(constraint.type) + && trivialConstraintTypeInferenceOracle.isSuitableResultedType(constraint.type) } } diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/KotlinCallCompleter.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/KotlinCallCompleter.kt index 5fb2bbf093e..5721f7741a2 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/KotlinCallCompleter.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/KotlinCallCompleter.kt @@ -53,7 +53,7 @@ class KotlinCallCompleter( return if (resolutionCallbacks.inferenceSession.shouldRunCompletion(candidate)) candidate.runCompletion( - CompletionModeCalculator.computeCompletionMode(candidate, expectedType, returnType), + CompletionModeCalculator.computeCompletionMode(candidate, expectedType, returnType, trivialConstraintTypeInferenceOracle), diagnosticHolder, resolutionCallbacks ) diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ExclExcl.fir.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ExclExcl.fir.kt index e7b403026f1..9d53b6c0473 100644 --- a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ExclExcl.fir.kt +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ExclExcl.fir.kt @@ -1,4 +1,3 @@ -// !WITH_NEW_INFERENCE fun bar(x: Int) = x + 1 fun f1(x: Int?) { diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ExclExcl.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ExclExcl.kt index 317f7af809c..7a28dad77a9 100644 --- a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ExclExcl.kt +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ExclExcl.kt @@ -1,4 +1,3 @@ -// !WITH_NEW_INFERENCE fun bar(x: Int) = x + 1 fun f1(x: Int?) {