[FIR] KT-56612: Fully-expand types when casting bare types

^KT-56612 Fixed

Merge-request: KT-MR-8849
Merged-by: Nikolay Lunyak <Nikolay.Lunyak@jetbrains.com>
This commit is contained in:
Nikolay Lunyak
2023-02-17 09:15:59 +00:00
committed by Space Team
parent 0963bd25a8
commit 516efe77c9
13 changed files with 163 additions and 10 deletions
@@ -4307,6 +4307,11 @@ public class LazyBodyIsNotTouchedTilContractsPhaseTestGenerated extends Abstract
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/types"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
}
@TestMetadata("bareWithDnnArg.kt")
public void testBareWithDnnArg() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/types/bareWithDnnArg.kt");
}
@TestMetadata("bareWithFlexibleArg.kt")
public void testBareWithFlexibleArg() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/types/bareWithFlexibleArg.kt");
@@ -0,0 +1,16 @@
FILE: main.kt
public abstract interface KotlinCancellablePromise<E> : R|Promise<E>| {
}
public final class D<T> : R|kotlin/Any| {
public constructor<T>(): R|D<T>| {
super<R|kotlin/Any|>()
}
public final fun foo(x: R|Promise<T & Any>|): R|kotlin/Unit| {
this@R|/D|.R|/D.bar|((R|<local>/x| as R|KotlinCancellablePromise<T & Any>|))
}
public final fun bar(x: R|KotlinCancellablePromise<T & Any>|): R|kotlin/Unit| {
}
}
@@ -0,0 +1,17 @@
// FIR_IDENTICAL
// SKIP_TXT
// FILE: Promise.java
public interface Promise<T> {}
// FILE: main.kt
interface KotlinCancellablePromise<E> : Promise<E>
class D<T> {
fun foo(x: Promise<T & Any>) {
bar(x as KotlinCancellablePromise)
}
fun bar(x: KotlinCancellablePromise<T & Any>) {}
}
@@ -4835,6 +4835,12 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/types"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
}
@Test
@TestMetadata("bareWithDnnArg.kt")
public void testBareWithDnnArg() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/types/bareWithDnnArg.kt");
}
@Test
@TestMetadata("bareWithFlexibleArg.kt")
public void testBareWithFlexibleArg() throws Exception {
@@ -4835,6 +4835,12 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/types"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
}
@Test
@TestMetadata("bareWithDnnArg.kt")
public void testBareWithDnnArg() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/types/bareWithDnnArg.kt");
}
@Test
@TestMetadata("bareWithFlexibleArg.kt")
public void testBareWithFlexibleArg() throws Exception {
@@ -489,6 +489,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
runTest("compiler/testData/diagnostics/tests/kt55733.kt");
}
@Test
@TestMetadata("kt56612.kt")
public void testKt56612() throws Exception {
runTest("compiler/testData/diagnostics/tests/kt56612.kt");
}
@Test
@TestMetadata("kt56665.kt")
public void testKt56665() throws Exception {
@@ -489,6 +489,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
runTest("compiler/testData/diagnostics/tests/kt55733.kt");
}
@Test
@TestMetadata("kt56612.kt")
public void testKt56612() throws Exception {
runTest("compiler/testData/diagnostics/tests/kt56612.kt");
}
@Test
@TestMetadata("kt56665.kt")
public void testKt56665() throws Exception {
@@ -6,6 +6,7 @@
package org.jetbrains.kotlin.fir.types
import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
import org.jetbrains.kotlin.fir.symbols.impl.FirTypeParameterSymbol
import org.jetbrains.kotlin.types.AbstractTypeChecker
import org.jetbrains.kotlin.types.model.KotlinTypeMarker
@@ -22,8 +23,8 @@ fun FirSession.doUnify(
targetTypeParameters: Set<FirTypeParameterSymbol>,
result: MutableMap<FirTypeParameterSymbol, ConeTypeProjection>,
): Boolean {
val originalType = originalTypeProjection.type?.lowerBoundIfFlexible()
val typeWithParameters = typeWithParametersProjection.type
val originalType = originalTypeProjection.type?.lowerBoundIfFlexible()?.fullyExpandedType(this)
val typeWithParameters = typeWithParametersProjection.type?.lowerBoundIfFlexible()?.fullyExpandedType(this)
if (originalType is ConeIntersectionType) {
val intersectionResult = mutableMapOf<FirTypeParameterSymbol, ConeTypeProjection>()
@@ -68,14 +69,6 @@ fun FirSession.doUnify(
return true
}
if (typeWithParameters is ConeFlexibleType) {
return doUnify(
originalTypeProjection,
typeWithParametersProjection.replaceType(typeWithParameters.lowerBound),
targetTypeParameters, result,
)
}
if (typeWithParameters is ConeDefinitelyNotNullType) {
return doUnify(
originalTypeProjection,