[FIR] Infer labeled type for lambda in return in catch ^KT-51009 Fixed

This commit is contained in:
Ivan Kochurkin
2022-01-28 22:56:38 +03:00
committed by teamcity
parent d82dff0e75
commit 30871fc08f
7 changed files with 51 additions and 1 deletions
@@ -14809,6 +14809,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
runTest("compiler/testData/diagnostics/tests/inference/completion/flexibleType.kt");
}
@Test
@TestMetadata("inferLabeledElementTypeForLambdaInReturnInCatch.kt")
public void testInferLabeledElementTypeForLambdaInReturnInCatch() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/completion/inferLabeledElementTypeForLambdaInReturnInCatch.kt");
}
@Test
@TestMetadata("intersectionType.kt")
public void testIntersectionType() throws Exception {
@@ -14809,6 +14809,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
runTest("compiler/testData/diagnostics/tests/inference/completion/flexibleType.kt");
}
@Test
@TestMetadata("inferLabeledElementTypeForLambdaInReturnInCatch.kt")
public void testInferLabeledElementTypeForLambdaInReturnInCatch() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/completion/inferLabeledElementTypeForLambdaInReturnInCatch.kt");
}
@Test
@TestMetadata("intersectionType.kt")
public void testIntersectionType() throws Exception {
@@ -14809,6 +14809,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
runTest("compiler/testData/diagnostics/tests/inference/completion/flexibleType.kt");
}
@Test
@TestMetadata("inferLabeledElementTypeForLambdaInReturnInCatch.kt")
public void testInferLabeledElementTypeForLambdaInReturnInCatch() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/completion/inferLabeledElementTypeForLambdaInReturnInCatch.kt");
}
@Test
@TestMetadata("intersectionType.kt")
public void testIntersectionType() throws Exception {
@@ -702,7 +702,8 @@ class FirCallCompletionResultsWriterTransformer(
return returnExpression
}
return super.transformReturnExpression(returnExpression, data)
val newData = labeledElement.returnTypeRef.coneTypeSafe<ConeKotlinType>()?.toExpectedType()
return super.transformReturnExpression(returnExpression, newData)
}
override fun transformBlock(block: FirBlock, data: ExpectedArgumentType?): FirStatement {
@@ -0,0 +1,20 @@
// FIR_IDENTICAL
// ISSUE: KT-51009
fun test(b: Boolean, f: () -> String?): () -> String {
val foo = try {
f
} catch (e: Exception) {
return { "1" } // Infer return type of test () -> String instead of type of `f`
}
return { "2" }
}
fun test2(b: Boolean, f: () -> String?) = run { // implicit return type
val foo = try {
f
} catch (e: Exception) {
return { "1" }
}
{ "2" }
}
@@ -0,0 +1,5 @@
package
public fun test(/*0*/ b: kotlin.Boolean, /*1*/ f: () -> kotlin.String?): () -> kotlin.String
public fun test2(/*0*/ b: kotlin.Boolean, /*1*/ f: () -> kotlin.String?): () -> kotlin.String
@@ -14815,6 +14815,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
runTest("compiler/testData/diagnostics/tests/inference/completion/flexibleType.kt");
}
@Test
@TestMetadata("inferLabeledElementTypeForLambdaInReturnInCatch.kt")
public void testInferLabeledElementTypeForLambdaInReturnInCatch() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/completion/inferLabeledElementTypeForLambdaInReturnInCatch.kt");
}
@Test
@TestMetadata("intersectionType.kt")
public void testIntersectionType() throws Exception {