[FE 1.0] Create DONT_CARE type only for callable references with no expected type
Otherwise, it can be resolved safety ^KT-52270 Fixed
This commit is contained in:
committed by
teamcity
parent
fb21937eb1
commit
2057deb91b
+6
@@ -3147,6 +3147,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/callableReference/kt51844.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt52270.kt")
|
||||
public void testKt52270() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/kt52270.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("nested.kt")
|
||||
public void testNested() throws Exception {
|
||||
|
||||
+1
-1
@@ -382,7 +382,7 @@ public class ExpressionTypingServices {
|
||||
)
|
||||
);
|
||||
|
||||
if (!isUnitExpectedType && statementExpression instanceof KtCallableReferenceExpression) {
|
||||
if (context.expectedType == NO_EXPECTED_TYPE && statementExpression instanceof KtCallableReferenceExpression) {
|
||||
KotlinTypeInfo typeInfo = createDontCareTypeInfoForNILambda(statementExpression, context);
|
||||
if (typeInfo != null) return typeInfo;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
// WITH_STDLIB
|
||||
|
||||
import kotlin.random.Random
|
||||
|
||||
fun fun1() {
|
||||
}
|
||||
|
||||
fun fun2() {
|
||||
}
|
||||
|
||||
fun takesLambda(lambda: () -> Unit) {
|
||||
lambda()
|
||||
}
|
||||
|
||||
fun takesOtherLambda(lambda: () -> Unit) = lambda()
|
||||
|
||||
fun foo() {}
|
||||
|
||||
fun bar2(): Int = 1
|
||||
fun <K> foo4(): K = 2 as K
|
||||
|
||||
fun test1(): String {
|
||||
takesOtherLambda {
|
||||
val reference: () -> Unit = if (Random.nextBoolean()) {
|
||||
::fun1
|
||||
} else {
|
||||
::fun2
|
||||
}
|
||||
takesLambda(reference)
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
|
||||
fun test2(): String {
|
||||
takesOtherLambda {
|
||||
val reference: () -> Unit = if (Random.nextBoolean())
|
||||
::fun1
|
||||
else
|
||||
::fun2
|
||||
takesLambda(reference)
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
|
||||
fun test3(): String {
|
||||
takesOtherLambda {
|
||||
val reference: () -> Unit = if (Random.nextBoolean()) {
|
||||
foo()
|
||||
::fun1
|
||||
} else {
|
||||
foo()
|
||||
::fun2
|
||||
}
|
||||
takesLambda(reference)
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return if (test1() == "OK" && test2() == "OK" && test3() == "OK") "OK" else "NOK"
|
||||
}
|
||||
+6
@@ -3051,6 +3051,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/callableReference/kt51844.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt52270.kt")
|
||||
public void testKt52270() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/kt52270.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("nested.kt")
|
||||
public void testNested() throws Exception {
|
||||
|
||||
+6
@@ -3147,6 +3147,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/callableReference/kt51844.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt52270.kt")
|
||||
public void testKt52270() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/kt52270.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("nested.kt")
|
||||
public void testNested() throws Exception {
|
||||
|
||||
+5
@@ -2673,6 +2673,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/callableReference/kt51844.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt52270.kt")
|
||||
public void testKt52270() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/kt52270.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("nested.kt")
|
||||
public void testNested() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/nested.kt");
|
||||
|
||||
+6
@@ -1989,6 +1989,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/callableReference/kt51844.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt52270.kt")
|
||||
public void testKt52270() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/kt52270.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("nested.kt")
|
||||
public void testNested() throws Exception {
|
||||
|
||||
+6
@@ -2031,6 +2031,12 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/callableReference/kt51844.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt52270.kt")
|
||||
public void testKt52270() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/kt52270.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("nested.kt")
|
||||
public void testNested() throws Exception {
|
||||
|
||||
+5
@@ -1813,6 +1813,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
|
||||
runTest("compiler/testData/codegen/box/callableReference/kt51844.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt52270.kt")
|
||||
public void testKt52270() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/kt52270.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("nested.kt")
|
||||
public void testNested() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/nested.kt");
|
||||
|
||||
+6
@@ -2083,6 +2083,12 @@ public class NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTest
|
||||
runTest("compiler/testData/codegen/box/callableReference/kt51844.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt52270.kt")
|
||||
public void testKt52270() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/kt52270.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("nested.kt")
|
||||
public void testNested() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user