[NI] Disallow full completion based on lower Nothing constraint
This commit is contained in:
+7
-3
@@ -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
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.components.KotlinConstraintSystemCompleter.ConstraintSystemCompletionMode
|
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.Constraint
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.model.VariableWithConstraints
|
import org.jetbrains.kotlin.resolve.calls.inference.model.VariableWithConstraints
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.KotlinResolutionCandidate
|
import org.jetbrains.kotlin.resolve.calls.model.KotlinResolutionCandidate
|
||||||
@@ -23,7 +24,8 @@ class CompletionModeCalculator {
|
|||||||
fun computeCompletionMode(
|
fun computeCompletionMode(
|
||||||
candidate: KotlinResolutionCandidate,
|
candidate: KotlinResolutionCandidate,
|
||||||
expectedType: UnwrappedType?,
|
expectedType: UnwrappedType?,
|
||||||
returnType: UnwrappedType?
|
returnType: UnwrappedType?,
|
||||||
|
trivialConstraintTypeInferenceOracle: TrivialConstraintTypeInferenceOracle
|
||||||
): ConstraintSystemCompletionMode = with(candidate) {
|
): ConstraintSystemCompletionMode = with(candidate) {
|
||||||
val csCompleterContext = getSystem().asConstraintSystemCompleterContext()
|
val csCompleterContext = getSystem().asConstraintSystemCompleterContext()
|
||||||
|
|
||||||
@@ -37,13 +39,14 @@ class CompletionModeCalculator {
|
|||||||
if (csBuilder.isProperType(returnType)) return ConstraintSystemCompletionMode.FULL
|
if (csBuilder.isProperType(returnType)) return ConstraintSystemCompletionMode.FULL
|
||||||
|
|
||||||
// For nested call with variables in return type check possibility of full completion
|
// 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 class CalculatorForNestedCall(
|
||||||
private val returnType: UnwrappedType?,
|
private val returnType: UnwrappedType?,
|
||||||
private val csCompleterContext: CsCompleterContext
|
private val csCompleterContext: CsCompleterContext,
|
||||||
|
private val trivialConstraintTypeInferenceOracle: TrivialConstraintTypeInferenceOracle
|
||||||
) {
|
) {
|
||||||
private enum class FixationDirection {
|
private enum class FixationDirection {
|
||||||
TO_SUBTYPE, EQUALITY
|
TO_SUBTYPE, EQUALITY
|
||||||
@@ -166,6 +169,7 @@ class CompletionModeCalculator {
|
|||||||
constraint.hasRequiredKind(direction)
|
constraint.hasRequiredKind(direction)
|
||||||
&& !constraint.type.typeConstructor().isIntegerLiteralTypeConstructor()
|
&& !constraint.type.typeConstructor().isIntegerLiteralTypeConstructor()
|
||||||
&& isProperType(constraint.type)
|
&& isProperType(constraint.type)
|
||||||
|
&& trivialConstraintTypeInferenceOracle.isSuitableResultedType(constraint.type)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -53,7 +53,7 @@ class KotlinCallCompleter(
|
|||||||
|
|
||||||
return if (resolutionCallbacks.inferenceSession.shouldRunCompletion(candidate))
|
return if (resolutionCallbacks.inferenceSession.shouldRunCompletion(candidate))
|
||||||
candidate.runCompletion(
|
candidate.runCompletion(
|
||||||
CompletionModeCalculator.computeCompletionMode(candidate, expectedType, returnType),
|
CompletionModeCalculator.computeCompletionMode(candidate, expectedType, returnType, trivialConstraintTypeInferenceOracle),
|
||||||
diagnosticHolder,
|
diagnosticHolder,
|
||||||
resolutionCallbacks
|
resolutionCallbacks
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// !WITH_NEW_INFERENCE
|
|
||||||
fun bar(x: Int) = x + 1
|
fun bar(x: Int) = x + 1
|
||||||
|
|
||||||
fun f1(x: Int?) {
|
fun f1(x: Int?) {
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// !WITH_NEW_INFERENCE
|
|
||||||
fun bar(x: Int) = x + 1
|
fun bar(x: Int) = x + 1
|
||||||
|
|
||||||
fun f1(x: Int?) {
|
fun f1(x: Int?) {
|
||||||
|
|||||||
Reference in New Issue
Block a user