FIR: Preserve K1 behavior for rawTypeValue ?: nothingTypedValue

It's been approximated to the non-raw version back then

^KT-54526 Fixed
This commit is contained in:
Denis.Zharkov
2022-10-24 12:58:22 +02:00
committed by Space Team
parent 52eb535a7d
commit 82100a414f
6 changed files with 50 additions and 1 deletions
@@ -24181,6 +24181,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
runTest("compiler/testData/diagnostics/tests/platformTypes/rawTypes/kt47459.kt");
}
@Test
@TestMetadata("lostRawTypeAfterElvis.kt")
public void testLostRawTypeAfterElvis() throws Exception {
runTest("compiler/testData/diagnostics/tests/platformTypes/rawTypes/lostRawTypeAfterElvis.kt");
}
@Test
@TestMetadata("noTypeArgumentsForRawScopedMembers.kt")
public void testNoTypeArgumentsForRawScopedMembers() throws Exception {
@@ -24181,6 +24181,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
runTest("compiler/testData/diagnostics/tests/platformTypes/rawTypes/kt47459.kt");
}
@Test
@TestMetadata("lostRawTypeAfterElvis.kt")
public void testLostRawTypeAfterElvis() throws Exception {
runTest("compiler/testData/diagnostics/tests/platformTypes/rawTypes/lostRawTypeAfterElvis.kt");
}
@Test
@TestMetadata("noTypeArgumentsForRawScopedMembers.kt")
public void testNoTypeArgumentsForRawScopedMembers() throws Exception {
@@ -24181,6 +24181,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
runTest("compiler/testData/diagnostics/tests/platformTypes/rawTypes/kt47459.kt");
}
@Test
@TestMetadata("lostRawTypeAfterElvis.kt")
public void testLostRawTypeAfterElvis() throws Exception {
runTest("compiler/testData/diagnostics/tests/platformTypes/rawTypes/lostRawTypeAfterElvis.kt");
}
@Test
@TestMetadata("noTypeArgumentsForRawScopedMembers.kt")
public void testNoTypeArgumentsForRawScopedMembers() throws Exception {
@@ -249,7 +249,10 @@ class FirControlFlowStatementsResolveTransformer(transformer: FirBodyResolveTran
if (result.rhs.typeRef.coneTypeSafe<ConeKotlinType>()?.isNothing == true) {
val lhsType = result.lhs.typeRef.coneTypeSafe<ConeKotlinType>()
if (lhsType != null) {
val newReturnType = lhsType.makeConeTypeDefinitelyNotNullOrNotNull(session.typeContext)
// Converting to non-raw type is necessary to preserver the K1 semantics (see KT-54526)
val newReturnType =
lhsType.makeConeTypeDefinitelyNotNullOrNotNull(session.typeContext)
.convertToNonRawVersion()
result.replaceTypeRef(result.typeRef.resolvedTypeFromPrototype(newReturnType))
isLhsNotNull = true
}
@@ -0,0 +1,22 @@
// SKIP_TXT
// FIR_IDENTICAL
// FILE: Generic.java
public class Generic<T> {
public static class ML<E> {}
public static Generic create() { return null; }
public <E> E foo(ML<E> w) { }
}
// FILE: main.kt
import Generic.ML
fun main(w: ML<String>) {
val generic2 = Generic.create() ?: return
// Not enough information to infer E (both K1 and K2 after KT-41794 is done)
// Because generic information is erased from the raw type scope of `generic1`
// But the parameter E is still there (that is a questionable behavior)
// `generic2` does have just non-raw type `Generic<Any!>..Generic<*>?`
generic2.foo(w).length // OK in K1, fails in K2 after KT-41794 is done
}
@@ -24187,6 +24187,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
runTest("compiler/testData/diagnostics/tests/platformTypes/rawTypes/kt47459.kt");
}
@Test
@TestMetadata("lostRawTypeAfterElvis.kt")
public void testLostRawTypeAfterElvis() throws Exception {
runTest("compiler/testData/diagnostics/tests/platformTypes/rawTypes/lostRawTypeAfterElvis.kt");
}
@Test
@TestMetadata("noTypeArgumentsForRawScopedMembers.kt")
public void testNoTypeArgumentsForRawScopedMembers() throws Exception {