[NI] Update type of complex subcall for last lambda expressions

This commit is contained in:
Mikhail Zarechenskiy
2020-02-25 10:45:21 +03:00
parent 66ef49cecc
commit 5393074d61
11 changed files with 70 additions and 2 deletions
@@ -77,6 +77,7 @@ class ResolvedAtomCompleter(
is ResolvedCallableReferenceAtom -> completeCallableReference(resolvedAtom)
is ResolvedLambdaAtom -> completeLambda(resolvedAtom)
is ResolvedCallAtom -> completeResolvedCall(resolvedAtom, emptyList())
is ResolvedSubCallArgument -> completeSubCallArgument(resolvedAtom)
is PartialCallResolutionResult -> completeResolvedCall(resolvedAtom.resultCallAtom, resolvedAtom.diagnostics)
}
}
@@ -90,6 +91,17 @@ class ResolvedAtomCompleter(
complete(resolvedAtom)
}
fun completeSubCallArgument(resolvedSubCallArgument: ResolvedSubCallArgument) {
val contextWithoutExpectedType = topLevelCallContext.replaceExpectedType(TypeUtils.NO_EXPECTED_TYPE)
kotlinToResolvedCallTransformer.updateRecordedType(
resolvedSubCallArgument.atom.psiExpression ?: return,
parameter = null,
context = contextWithoutExpectedType,
reportErrorForTypeMismatch = true,
convertedArgumentType = null
)
}
fun completeResolvedCall(resolvedCallAtom: ResolvedCallAtom, diagnostics: Collection<KotlinCallDiagnostic>): ResolvedCall<*>? {
clearPartiallyResolvedCall(resolvedCallAtom)
@@ -179,7 +179,7 @@ private fun checkSubCallArgument(
diagnosticsHolder: KotlinDiagnosticsHolder,
receiverInfo: ReceiverInfo,
): ResolvedAtom {
val subCallResult = subCallArgument.callResult
val subCallResult = ResolvedSubCallArgument(subCallArgument)
if (expectedType == null) return subCallResult
@@ -44,7 +44,7 @@ interface SimpleKotlinCallArgument : KotlinCallArgument, ReceiverKotlinCallArgum
interface ExpressionKotlinCallArgument : SimpleKotlinCallArgument, ResolutionAtom
interface SubKotlinCallArgument : SimpleKotlinCallArgument {
interface SubKotlinCallArgument : SimpleKotlinCallArgument, ResolutionAtom {
val callResult: PartialCallResolutionResult
}
@@ -85,6 +85,12 @@ class ResolvedExpressionAtom(override val atom: ExpressionKotlinCallArgument) :
}
}
class ResolvedSubCallArgument(override val atom: SubKotlinCallArgument) : ResolvedAtom() {
init {
setAnalyzedResults(listOf(atom.callResult))
}
}
interface PostponedResolvedAtomMarker {
val inputTypes: Collection<KotlinTypeMarker>
val outputType: KotlinTypeMarker?
@@ -0,0 +1,20 @@
class Inv<T>
fun Inv<*>.invToInv(): Inv<*>? = null
fun <R> myRun(block: () -> R): R {
return block()
}
fun test(c: Inv<*>) {
myRun {
if (true) return@myRun // coerction to Unit
c.invToInv()?.let {}
}
}
fun box(): String {
test(Inv<Int>())
return "OK"
}
@@ -12770,6 +12770,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/inference/coercionToUnitWithLastLambdaExpression.kt");
}
@TestMetadata("coerctionToUnitForLastExpressionWithStarProjection.kt")
public void testCoerctionToUnitForLastExpressionWithStarProjection() throws Exception {
runTest("compiler/testData/codegen/box/inference/coerctionToUnitForLastExpressionWithStarProjection.kt");
}
@TestMetadata("integerLiteralTypeInLamdaReturnType.kt")
public void testIntegerLiteralTypeInLamdaReturnType() throws Exception {
runTest("compiler/testData/codegen/box/inference/integerLiteralTypeInLamdaReturnType.kt");
@@ -12770,6 +12770,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/inference/coercionToUnitWithLastLambdaExpression.kt");
}
@TestMetadata("coerctionToUnitForLastExpressionWithStarProjection.kt")
public void testCoerctionToUnitForLastExpressionWithStarProjection() throws Exception {
runTest("compiler/testData/codegen/box/inference/coerctionToUnitForLastExpressionWithStarProjection.kt");
}
@TestMetadata("integerLiteralTypeInLamdaReturnType.kt")
public void testIntegerLiteralTypeInLamdaReturnType() throws Exception {
runTest("compiler/testData/codegen/box/inference/integerLiteralTypeInLamdaReturnType.kt");
@@ -11640,6 +11640,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTest("compiler/testData/codegen/box/inference/coercionToUnitWithLastLambdaExpression.kt");
}
@TestMetadata("coerctionToUnitForLastExpressionWithStarProjection.kt")
public void testCoerctionToUnitForLastExpressionWithStarProjection() throws Exception {
runTest("compiler/testData/codegen/box/inference/coerctionToUnitForLastExpressionWithStarProjection.kt");
}
@TestMetadata("integerLiteralTypeInLamdaReturnType.kt")
public void testIntegerLiteralTypeInLamdaReturnType() throws Exception {
runTest("compiler/testData/codegen/box/inference/integerLiteralTypeInLamdaReturnType.kt");
@@ -11640,6 +11640,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/inference/coercionToUnitWithLastLambdaExpression.kt");
}
@TestMetadata("coerctionToUnitForLastExpressionWithStarProjection.kt")
public void testCoerctionToUnitForLastExpressionWithStarProjection() throws Exception {
runTest("compiler/testData/codegen/box/inference/coerctionToUnitForLastExpressionWithStarProjection.kt");
}
@TestMetadata("integerLiteralTypeInLamdaReturnType.kt")
public void testIntegerLiteralTypeInLamdaReturnType() throws Exception {
runTest("compiler/testData/codegen/box/inference/integerLiteralTypeInLamdaReturnType.kt");
@@ -9990,6 +9990,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/inference/coercionToUnitWithLastLambdaExpression.kt");
}
@TestMetadata("coerctionToUnitForLastExpressionWithStarProjection.kt")
public void testCoerctionToUnitForLastExpressionWithStarProjection() throws Exception {
runTest("compiler/testData/codegen/box/inference/coerctionToUnitForLastExpressionWithStarProjection.kt");
}
@TestMetadata("integerLiteralTypeInLamdaReturnType.kt")
public void testIntegerLiteralTypeInLamdaReturnType() throws Exception {
runTest("compiler/testData/codegen/box/inference/integerLiteralTypeInLamdaReturnType.kt");
@@ -10055,6 +10055,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/inference/coercionToUnitWithLastLambdaExpression.kt");
}
@TestMetadata("coerctionToUnitForLastExpressionWithStarProjection.kt")
public void testCoerctionToUnitForLastExpressionWithStarProjection() throws Exception {
runTest("compiler/testData/codegen/box/inference/coerctionToUnitForLastExpressionWithStarProjection.kt");
}
@TestMetadata("integerLiteralTypeInLamdaReturnType.kt")
public void testIntegerLiteralTypeInLamdaReturnType() throws Exception {
runTest("compiler/testData/codegen/box/inference/integerLiteralTypeInLamdaReturnType.kt");