[FIR] Fix CAST_NEVER_SUCCEEDS for definitely not null types

This commit is contained in:
Ivan Kochurkin
2023-10-26 20:37:26 +02:00
committed by Space Team
parent 0efcad51e9
commit df43226a08
7 changed files with 38 additions and 2 deletions
@@ -5767,6 +5767,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
runTest("compiler/testData/diagnostics/tests/cast/neverSucceeds/CastToNotNullSuper.kt");
}
@Test
@TestMetadata("DefinitelyNotNullTypes.kt")
public void testDefinitelyNotNullTypes() throws Exception {
runTest("compiler/testData/diagnostics/tests/cast/neverSucceeds/DefinitelyNotNullTypes.kt");
}
@Test
@TestMetadata("MappedDirect.kt")
public void testMappedDirect() throws Exception {
@@ -5767,6 +5767,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
runTest("compiler/testData/diagnostics/tests/cast/neverSucceeds/CastToNotNullSuper.kt");
}
@Test
@TestMetadata("DefinitelyNotNullTypes.kt")
public void testDefinitelyNotNullTypes() throws Exception {
runTest("compiler/testData/diagnostics/tests/cast/neverSucceeds/DefinitelyNotNullTypes.kt");
}
@Test
@TestMetadata("MappedDirect.kt")
public void testMappedDirect() throws Exception {
@@ -5761,6 +5761,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
runTest("compiler/testData/diagnostics/tests/cast/neverSucceeds/CastToNotNullSuper.kt");
}
@Test
@TestMetadata("DefinitelyNotNullTypes.kt")
public void testDefinitelyNotNullTypes() throws Exception {
runTest("compiler/testData/diagnostics/tests/cast/neverSucceeds/DefinitelyNotNullTypes.kt");
}
@Test
@TestMetadata("MappedDirect.kt")
public void testMappedDirect() throws Exception {
@@ -5767,6 +5767,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
runTest("compiler/testData/diagnostics/tests/cast/neverSucceeds/CastToNotNullSuper.kt");
}
@Test
@TestMetadata("DefinitelyNotNullTypes.kt")
public void testDefinitelyNotNullTypes() throws Exception {
runTest("compiler/testData/diagnostics/tests/cast/neverSucceeds/DefinitelyNotNullTypes.kt");
}
@Test
@TestMetadata("MappedDirect.kt")
public void testMappedDirect() throws Exception {
@@ -32,8 +32,8 @@ fun checkCasting(
isSafeCase: Boolean,
context: CheckerContext
): CastingType {
val lhsLowerType = lhsType.lowerBoundIfFlexible()
val rhsLowerType = rhsType.lowerBoundIfFlexible()
val lhsLowerType = lhsType.lowerBoundIfFlexible().originalIfDefinitelyNotNullable()
val rhsLowerType = rhsType.lowerBoundIfFlexible().originalIfDefinitelyNotNullable()
if (lhsLowerType is ConeErrorType || rhsLowerType is ConeErrorType) return CastingType.Possible
@@ -0,0 +1,6 @@
// FIR_IDENTICAL
fun <T, K> test(x: T & Any) {
x <!USELESS_CAST!>as (T & Any)<!>
x <!UNCHECKED_CAST!>as (K & Any)<!>
}
@@ -5767,6 +5767,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
runTest("compiler/testData/diagnostics/tests/cast/neverSucceeds/CastToNotNullSuper.kt");
}
@Test
@TestMetadata("DefinitelyNotNullTypes.kt")
public void testDefinitelyNotNullTypes() throws Exception {
runTest("compiler/testData/diagnostics/tests/cast/neverSucceeds/DefinitelyNotNullTypes.kt");
}
@Test
@TestMetadata("MappedDirect.kt")
public void testMappedDirect() throws Exception {