[NI] Add support ExpectedTypeFromCast to new inference. #KT-30405 Fixed
This commit is contained in:
+2
@@ -49,6 +49,8 @@ interface KotlinResolutionCallbacks {
|
||||
fun isCompileTimeConstant(resolvedAtom: ResolvedCallAtom, expectedType: UnwrappedType): Boolean
|
||||
|
||||
val inferenceSession: InferenceSession
|
||||
|
||||
fun getExpectedTypeFromAsExpressionAndRecordItInTrace(resolvedAtom: ResolvedCallAtom): UnwrappedType?
|
||||
}
|
||||
|
||||
interface SamConversionTransformer {
|
||||
|
||||
+12
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.resolve.calls.components
|
||||
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.NewConstraintSystem
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.components.KotlinConstraintSystemCompleter
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.components.KotlinConstraintSystemCompleter.ConstraintSystemCompletionMode
|
||||
@@ -42,6 +43,7 @@ class KotlinCallCompleter(
|
||||
val returnType = candidate.returnTypeWithSmartCastInfo(resolutionCallbacks)
|
||||
|
||||
candidate.addExpectedTypeConstraint(returnType, expectedType, resolutionCallbacks)
|
||||
candidate.addExpectedTypeFromCastConstraint(returnType, resolutionCallbacks)
|
||||
|
||||
return if (resolutionCallbacks.inferenceSession.shouldRunCompletion(candidate))
|
||||
candidate.runCompletion(
|
||||
@@ -155,6 +157,16 @@ class KotlinCallCompleter(
|
||||
}
|
||||
}
|
||||
|
||||
private fun KotlinResolutionCandidate.addExpectedTypeFromCastConstraint(
|
||||
returnType: UnwrappedType?,
|
||||
resolutionCallbacks: KotlinResolutionCallbacks
|
||||
) {
|
||||
if (!callComponents.languageVersionSettings.supportsFeature(LanguageFeature.ExpectedTypeFromCast)) return
|
||||
if (returnType == null) return
|
||||
val expectedType = resolutionCallbacks.getExpectedTypeFromAsExpressionAndRecordItInTrace(resolvedCall) ?: return
|
||||
csBuilder.addSubtypeConstraint(returnType, expectedType, ExpectedTypeConstraintPosition(resolvedCall.atom))
|
||||
}
|
||||
|
||||
private fun KotlinResolutionCandidate.computeCompletionMode(
|
||||
expectedType: UnwrappedType?,
|
||||
currentReturnType: UnwrappedType?
|
||||
|
||||
Reference in New Issue
Block a user