FirCallCompleter: unwrap definitely not-null type properly
#KT-50180 Fixed
This commit is contained in:
+6
@@ -5555,6 +5555,12 @@ public class DiagnosisCompilerFirTestdataTestGenerated extends AbstractDiagnosis
|
|||||||
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/problems/DeepCopyIrTree.kt");
|
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/problems/DeepCopyIrTree.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("definitelyNotNullCast.kt")
|
||||||
|
public void testDefinitelyNotNullCast() throws Exception {
|
||||||
|
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/problems/definitelyNotNullCast.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("EnumMapGet.kt")
|
@TestMetadata("EnumMapGet.kt")
|
||||||
public void testEnumMapGet() throws Exception {
|
public void testEnumMapGet() throws Exception {
|
||||||
|
|||||||
Vendored
+14
@@ -0,0 +1,14 @@
|
|||||||
|
FILE: test.kt
|
||||||
|
public open class Value : R|kotlin/Any| {
|
||||||
|
public constructor(s: R|kotlin/String|): R|Value| {
|
||||||
|
super<R|kotlin/Any|>()
|
||||||
|
}
|
||||||
|
|
||||||
|
public final val s: R|kotlin/String| = R|<local>/s|
|
||||||
|
public get(): R|kotlin/String|
|
||||||
|
|
||||||
|
}
|
||||||
|
public final val generator: R|Generator| = R|/Generator.Generator|()
|
||||||
|
public get(): R|Generator|
|
||||||
|
public final val y: R|Value| = (R|/generator|.R|/Generator.createValue|<R|ft<Value, Value?>|>(String(Omega)) as R|Value|)
|
||||||
|
public get(): R|Value|
|
||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
// FILE: Generator.java
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class Generator {
|
||||||
|
@NotNull
|
||||||
|
public <T extends Value> T createValue(@NotNull String content) {
|
||||||
|
return (T) (new Value(content));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: test.kt
|
||||||
|
open class Value(val s: String)
|
||||||
|
|
||||||
|
val generator = Generator()
|
||||||
|
|
||||||
|
val y = generator.createValue("Omega") <!USELESS_CAST!>as Value<!>
|
||||||
+6
@@ -5555,6 +5555,12 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
|
|||||||
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/problems/DeepCopyIrTree.kt");
|
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/problems/DeepCopyIrTree.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("definitelyNotNullCast.kt")
|
||||||
|
public void testDefinitelyNotNullCast() throws Exception {
|
||||||
|
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/problems/definitelyNotNullCast.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("EnumMapGet.kt")
|
@TestMetadata("EnumMapGet.kt")
|
||||||
public void testEnumMapGet() throws Exception {
|
public void testEnumMapGet() throws Exception {
|
||||||
|
|||||||
+6
@@ -5555,6 +5555,12 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
|
|||||||
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/problems/DeepCopyIrTree.kt");
|
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/problems/DeepCopyIrTree.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("definitelyNotNullCast.kt")
|
||||||
|
public void testDefinitelyNotNullCast() throws Exception {
|
||||||
|
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/problems/definitelyNotNullCast.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("EnumMapGet.kt")
|
@TestMetadata("EnumMapGet.kt")
|
||||||
public void testEnumMapGet() throws Exception {
|
public void testEnumMapGet() throws Exception {
|
||||||
|
|||||||
+6
-2
@@ -345,14 +345,18 @@ internal fun FirFunction.isFunctionForExpectTypeFromCastFeature(): Boolean {
|
|||||||
|
|
||||||
val returnType = returnTypeRef.coneTypeSafe<ConeKotlinType>() ?: return false
|
val returnType = returnTypeRef.coneTypeSafe<ConeKotlinType>() ?: return false
|
||||||
|
|
||||||
if ((returnType.lowerBoundIfFlexible() as? ConeTypeParameterType)?.lookupTag != typeParameter.symbol.toLookupTag()) return false
|
if ((returnType.unwrap() as? ConeTypeParameterType)?.lookupTag != typeParameter.symbol.toLookupTag()) return false
|
||||||
|
|
||||||
fun FirTypeRef.isBadType() =
|
fun FirTypeRef.isBadType() =
|
||||||
coneTypeSafe<ConeKotlinType>()
|
coneTypeSafe<ConeKotlinType>()
|
||||||
?.contains { (it.lowerBoundIfFlexible() as? ConeTypeParameterType)?.lookupTag == typeParameter.symbol.toLookupTag() } != false
|
?.contains { (it.unwrap() as? ConeTypeParameterType)?.lookupTag == typeParameter.symbol.toLookupTag() } != false
|
||||||
|
|
||||||
if (valueParameters.any { it.returnTypeRef.isBadType() } || receiverTypeRef?.isBadType() == true) return false
|
if (valueParameters.any { it.returnTypeRef.isBadType() } || receiverTypeRef?.isBadType() == true) return false
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun ConeKotlinType.unwrap(): ConeSimpleKotlinType = lowerBoundIfFlexible().let {
|
||||||
|
if (it is ConeDefinitelyNotNullType) it.original.unwrap() else it
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user