K2: Fix false-positive UNSAFE_CALL on safe call with flexible type alias
The idea of the fix is just unwrapping flexible version of type alias, before creating a not-nullable version for safe-call subject. Otherwise, it was remained to be JsExpressionResult after applying makeConeTypeDefinitelyNotNullOrNotNull (and the type is still nullable) ^KT-57190 Fixed
This commit is contained in:
committed by
Space Team
parent
bf977d4262
commit
823c60a7dc
+16
@@ -27811,6 +27811,22 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/diagnostics/tests/safeCalls")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
public class SafeCalls {
|
||||
@Test
|
||||
public void testAllFilesPresentInSafeCalls() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/safeCalls"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.(fir|ll)\\.kts?$"), true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("safeCallOnFlexibleTypeAlias.kt")
|
||||
public void testSafeCallOnFlexibleTypeAlias() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/safeCalls/safeCallOnFlexibleTypeAlias.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/diagnostics/tests/samConversions")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
|
||||
+16
@@ -27811,6 +27811,22 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/diagnostics/tests/safeCalls")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
public class SafeCalls {
|
||||
@Test
|
||||
public void testAllFilesPresentInSafeCalls() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/safeCalls"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.(fir|ll)\\.kts?$"), true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("safeCallOnFlexibleTypeAlias.kt")
|
||||
public void testSafeCallOnFlexibleTypeAlias() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/safeCalls/safeCallOnFlexibleTypeAlias.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/diagnostics/tests/samConversions")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
|
||||
+16
@@ -27823,6 +27823,22 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/diagnostics/tests/safeCalls")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
public class SafeCalls {
|
||||
@Test
|
||||
public void testAllFilesPresentInSafeCalls() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/safeCalls"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.(fir|ll)\\.kts?$"), true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("safeCallOnFlexibleTypeAlias.kt")
|
||||
public void testSafeCallOnFlexibleTypeAlias() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/safeCalls/safeCallOnFlexibleTypeAlias.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/diagnostics/tests/samConversions")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
|
||||
@@ -482,7 +482,7 @@ fun FirCheckedSafeCallSubject.propagateTypeFromOriginalReceiver(
|
||||
?: nullableReceiverExpression.typeRef)
|
||||
.coneTypeSafe<ConeKotlinType>() ?: return
|
||||
|
||||
val expandedReceiverType = if (receiverType is ConeClassLikeType) receiverType.fullyExpandedType(session) else receiverType
|
||||
val expandedReceiverType = receiverType.fullyExpandedType(session)
|
||||
|
||||
val resolvedTypeRef =
|
||||
typeRef.resolvedTypeFromPrototype(expandedReceiverType.makeConeTypeDefinitelyNotNullOrNotNull(session.typeContext))
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
// FIR_IDENTICAL
|
||||
// ISSUE: KT-57190
|
||||
// FILE: MyFunction.java
|
||||
@FunctionalInterface
|
||||
public interface MyFunction<T> {
|
||||
void apply(T t);
|
||||
}
|
||||
|
||||
// FILE: MyPromise.java
|
||||
public interface MyPromise<T> {
|
||||
void then(MyFunction<T> done);
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
typealias JsExpressionResult = String?
|
||||
|
||||
fun countElementsByXpathAsync(promise: MyPromise<JsExpressionResult>, t: JsExpressionResult) {
|
||||
promise.then {
|
||||
it?.foo() // K1: ok, K2: was UNSAFE_CALL
|
||||
}
|
||||
}
|
||||
|
||||
fun String.foo() {}
|
||||
Generated
+16
@@ -27823,6 +27823,22 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/diagnostics/tests/safeCalls")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
public class SafeCalls {
|
||||
@Test
|
||||
public void testAllFilesPresentInSafeCalls() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/safeCalls"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.(fir|ll)\\.kts?$"), true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("safeCallOnFlexibleTypeAlias.kt")
|
||||
public void testSafeCallOnFlexibleTypeAlias() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/safeCalls/safeCallOnFlexibleTypeAlias.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/diagnostics/tests/samConversions")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
|
||||
Reference in New Issue
Block a user