FIR: Fix inference of nullable unit lambda at RHS of elvis
This commit is contained in:
committed by
teamcityserver
parent
46217318c0
commit
c0a46eaefd
+6
@@ -14060,6 +14060,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
|
|||||||
runTest("compiler/testData/diagnostics/tests/inference/coercionToUnit/kt30242.kt");
|
runTest("compiler/testData/diagnostics/tests/inference/coercionToUnit/kt30242.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("lambdaWithNullableUnitInElvis.kt")
|
||||||
|
public void testLambdaWithNullableUnitInElvis() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/inference/coercionToUnit/lambdaWithNullableUnitInElvis.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("noCoercion.kt")
|
@TestMetadata("noCoercion.kt")
|
||||||
public void testNoCoercion() throws Exception {
|
public void testNoCoercion() throws Exception {
|
||||||
|
|||||||
+6
@@ -14060,6 +14060,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
|
|||||||
runTest("compiler/testData/diagnostics/tests/inference/coercionToUnit/kt30242.kt");
|
runTest("compiler/testData/diagnostics/tests/inference/coercionToUnit/kt30242.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("lambdaWithNullableUnitInElvis.kt")
|
||||||
|
public void testLambdaWithNullableUnitInElvis() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/inference/coercionToUnit/lambdaWithNullableUnitInElvis.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("noCoercion.kt")
|
@TestMetadata("noCoercion.kt")
|
||||||
public void testNoCoercion() throws Exception {
|
public void testNoCoercion() throws Exception {
|
||||||
|
|||||||
+6
@@ -14060,6 +14060,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
|
|||||||
runTest("compiler/testData/diagnostics/tests/inference/coercionToUnit/kt30242.kt");
|
runTest("compiler/testData/diagnostics/tests/inference/coercionToUnit/kt30242.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("lambdaWithNullableUnitInElvis.kt")
|
||||||
|
public void testLambdaWithNullableUnitInElvis() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/inference/coercionToUnit/lambdaWithNullableUnitInElvis.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("noCoercion.kt")
|
@TestMetadata("noCoercion.kt")
|
||||||
public void testNoCoercion() throws Exception {
|
public void testNoCoercion() throws Exception {
|
||||||
|
|||||||
+2
-1
@@ -787,8 +787,9 @@ open class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransfor
|
|||||||
val implicitReturns = returnExpressionsExceptLast.filter {
|
val implicitReturns = returnExpressionsExceptLast.filter {
|
||||||
(it as? FirExpression)?.typeRef is FirImplicitUnitTypeRef
|
(it as? FirExpression)?.typeRef is FirImplicitUnitTypeRef
|
||||||
}
|
}
|
||||||
|
|
||||||
val returnType =
|
val returnType =
|
||||||
if (implicitReturns.isNotEmpty()) {
|
if (implicitReturns.isNotEmpty() || lambda.returnType?.isUnit == true) {
|
||||||
// i.e., early return, e.g., l@{ ... return@l ... }
|
// i.e., early return, e.g., l@{ ... return@l ... }
|
||||||
// Note that the last statement will be coerced to Unit if needed.
|
// Note that the last statement will be coerced to Unit if needed.
|
||||||
session.builtinTypes.unitType.type
|
session.builtinTypes.unitType.type
|
||||||
|
|||||||
Vendored
+8
@@ -0,0 +1,8 @@
|
|||||||
|
// FIR_IDENTICAL
|
||||||
|
// SKIP_TXT
|
||||||
|
|
||||||
|
fun nullableF(): (() -> Unit)?= null
|
||||||
|
|
||||||
|
fun String.unit() {}
|
||||||
|
|
||||||
|
fun foo(x: String?): () -> Unit = nullableF() ?: { x?.unit() }
|
||||||
Generated
+6
@@ -14066,6 +14066,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
|||||||
runTest("compiler/testData/diagnostics/tests/inference/coercionToUnit/kt30242.kt");
|
runTest("compiler/testData/diagnostics/tests/inference/coercionToUnit/kt30242.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("lambdaWithNullableUnitInElvis.kt")
|
||||||
|
public void testLambdaWithNullableUnitInElvis() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/inference/coercionToUnit/lambdaWithNullableUnitInElvis.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("noCoercion.kt")
|
@TestMetadata("noCoercion.kt")
|
||||||
public void testNoCoercion() throws Exception {
|
public void testNoCoercion() throws Exception {
|
||||||
|
|||||||
Reference in New Issue
Block a user