[FIR] Add equality constraint from expected type for some synthetic function calls
This fixes some cases where we infer some type variable inside one of the branches to Nothing instead of the expected type because Nothing appeared in some other branch. Specifically, we add an equality instead of a subtype constraint during completion of calls to synthetic functions for if/when, try and !!. We don't do it when the call contains a (possibly nested) elvis or is inside the RHS of an assignment. Otherwise, we would prevent some smart-casts. #KT-65882 Fixed
This commit is contained in:
committed by
Space Team
parent
eaef7122f6
commit
69a7bf7f68
+18
@@ -16652,6 +16652,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
|
||||
runTest("compiler/testData/diagnostics/tests/inference/capturedTypesInSelfType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("checkNotNullWithNullableExpectedType.kt")
|
||||
public void testCheckNotNullWithNullableExpectedType() {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/checkNotNullWithNullableExpectedType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("coerceFunctionLiteralToSuspend.kt")
|
||||
public void testCoerceFunctionLiteralToSuspend() {
|
||||
@@ -17174,6 +17180,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
|
||||
runTest("compiler/testData/diagnostics/tests/inference/mostSpecificAfterInference.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("nestedIfWithExpectedType.kt")
|
||||
public void testNestedIfWithExpectedType() {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/nestedIfWithExpectedType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("NoInferenceFromDeclaredBounds.kt")
|
||||
public void testNoInferenceFromDeclaredBounds() {
|
||||
@@ -18982,6 +18994,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
|
||||
public void testWrongApproximationWithDefNotNullTypesAndDelegates() {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/constraints/wrongApproximationWithDefNotNullTypesAndDelegates.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("wrongExpectedTypeForWhen.kt")
|
||||
public void testWrongExpectedTypeForWhen() {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/constraints/wrongExpectedTypeForWhen.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
|
||||
+6
@@ -23888,6 +23888,12 @@ public class LLFirBlackBoxCodegenBasedTestGenerated extends AbstractLLFirBlackBo
|
||||
runTest("compiler/testData/codegen/box/inference/kt51040.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt65882.kt")
|
||||
public void testKt65882() {
|
||||
runTest("compiler/testData/codegen/box/inference/kt65882.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("lambdaWithStarReturn.kt")
|
||||
public void testLambdaWithStarReturn() {
|
||||
|
||||
+18
@@ -16652,6 +16652,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
|
||||
runTest("compiler/testData/diagnostics/tests/inference/capturedTypesInSelfType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("checkNotNullWithNullableExpectedType.kt")
|
||||
public void testCheckNotNullWithNullableExpectedType() {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/checkNotNullWithNullableExpectedType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("coerceFunctionLiteralToSuspend.kt")
|
||||
public void testCoerceFunctionLiteralToSuspend() {
|
||||
@@ -17174,6 +17180,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
|
||||
runTest("compiler/testData/diagnostics/tests/inference/mostSpecificAfterInference.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("nestedIfWithExpectedType.kt")
|
||||
public void testNestedIfWithExpectedType() {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/nestedIfWithExpectedType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("NoInferenceFromDeclaredBounds.kt")
|
||||
public void testNoInferenceFromDeclaredBounds() {
|
||||
@@ -18982,6 +18994,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
|
||||
public void testWrongApproximationWithDefNotNullTypesAndDelegates() {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/constraints/wrongApproximationWithDefNotNullTypesAndDelegates.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("wrongExpectedTypeForWhen.kt")
|
||||
public void testWrongExpectedTypeForWhen() {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/constraints/wrongExpectedTypeForWhen.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
|
||||
+6
@@ -23888,6 +23888,12 @@ public class LLFirReversedBlackBoxCodegenBasedTestGenerated extends AbstractLLFi
|
||||
runTest("compiler/testData/codegen/box/inference/kt51040.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt65882.kt")
|
||||
public void testKt65882() {
|
||||
runTest("compiler/testData/codegen/box/inference/kt65882.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("lambdaWithStarReturn.kt")
|
||||
public void testLambdaWithStarReturn() {
|
||||
|
||||
Reference in New Issue
Block a user