[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:
committed by
Space Team
parent
0963bd25a8
commit
516efe77c9
+6
@@ -4835,6 +4835,12 @@ public class DiagnosisCompilerFirTestdataTestGenerated extends AbstractDiagnosis
|
|||||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/types"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
|
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
|
@Test
|
||||||
@TestMetadata("bareWithFlexibleArg.kt")
|
@TestMetadata("bareWithFlexibleArg.kt")
|
||||||
public void testBareWithFlexibleArg() throws Exception {
|
public void testBareWithFlexibleArg() throws Exception {
|
||||||
|
|||||||
+6
@@ -489,6 +489,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
|
|||||||
runTest("compiler/testData/diagnostics/tests/kt55733.kt");
|
runTest("compiler/testData/diagnostics/tests/kt55733.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kt56612.kt")
|
||||||
|
public void testKt56612() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/kt56612.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("kt56665.kt")
|
@TestMetadata("kt56665.kt")
|
||||||
public void testKt56665() throws Exception {
|
public void testKt56665() throws Exception {
|
||||||
|
|||||||
+5
@@ -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);
|
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")
|
@TestMetadata("bareWithFlexibleArg.kt")
|
||||||
public void testBareWithFlexibleArg() throws Exception {
|
public void testBareWithFlexibleArg() throws Exception {
|
||||||
runTest("compiler/fir/analysis-tests/testData/resolve/types/bareWithFlexibleArg.kt");
|
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>) {}
|
||||||
|
}
|
||||||
+6
@@ -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);
|
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
|
@Test
|
||||||
@TestMetadata("bareWithFlexibleArg.kt")
|
@TestMetadata("bareWithFlexibleArg.kt")
|
||||||
public void testBareWithFlexibleArg() throws Exception {
|
public void testBareWithFlexibleArg() throws Exception {
|
||||||
|
|||||||
+6
@@ -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);
|
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
|
@Test
|
||||||
@TestMetadata("bareWithFlexibleArg.kt")
|
@TestMetadata("bareWithFlexibleArg.kt")
|
||||||
public void testBareWithFlexibleArg() throws Exception {
|
public void testBareWithFlexibleArg() throws Exception {
|
||||||
|
|||||||
+6
@@ -489,6 +489,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
|
|||||||
runTest("compiler/testData/diagnostics/tests/kt55733.kt");
|
runTest("compiler/testData/diagnostics/tests/kt55733.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kt56612.kt")
|
||||||
|
public void testKt56612() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/kt56612.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("kt56665.kt")
|
@TestMetadata("kt56665.kt")
|
||||||
public void testKt56665() throws Exception {
|
public void testKt56665() throws Exception {
|
||||||
|
|||||||
+6
@@ -489,6 +489,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
|
|||||||
runTest("compiler/testData/diagnostics/tests/kt55733.kt");
|
runTest("compiler/testData/diagnostics/tests/kt55733.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kt56612.kt")
|
||||||
|
public void testKt56612() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/kt56612.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("kt56665.kt")
|
@TestMetadata("kt56665.kt")
|
||||||
public void testKt56665() throws Exception {
|
public void testKt56665() throws Exception {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
package org.jetbrains.kotlin.fir.types
|
package org.jetbrains.kotlin.fir.types
|
||||||
|
|
||||||
import org.jetbrains.kotlin.fir.FirSession
|
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.fir.symbols.impl.FirTypeParameterSymbol
|
||||||
import org.jetbrains.kotlin.types.AbstractTypeChecker
|
import org.jetbrains.kotlin.types.AbstractTypeChecker
|
||||||
import org.jetbrains.kotlin.types.model.KotlinTypeMarker
|
import org.jetbrains.kotlin.types.model.KotlinTypeMarker
|
||||||
@@ -22,8 +23,8 @@ fun FirSession.doUnify(
|
|||||||
targetTypeParameters: Set<FirTypeParameterSymbol>,
|
targetTypeParameters: Set<FirTypeParameterSymbol>,
|
||||||
result: MutableMap<FirTypeParameterSymbol, ConeTypeProjection>,
|
result: MutableMap<FirTypeParameterSymbol, ConeTypeProjection>,
|
||||||
): Boolean {
|
): Boolean {
|
||||||
val originalType = originalTypeProjection.type?.lowerBoundIfFlexible()
|
val originalType = originalTypeProjection.type?.lowerBoundIfFlexible()?.fullyExpandedType(this)
|
||||||
val typeWithParameters = typeWithParametersProjection.type
|
val typeWithParameters = typeWithParametersProjection.type?.lowerBoundIfFlexible()?.fullyExpandedType(this)
|
||||||
|
|
||||||
if (originalType is ConeIntersectionType) {
|
if (originalType is ConeIntersectionType) {
|
||||||
val intersectionResult = mutableMapOf<FirTypeParameterSymbol, ConeTypeProjection>()
|
val intersectionResult = mutableMapOf<FirTypeParameterSymbol, ConeTypeProjection>()
|
||||||
@@ -68,14 +69,6 @@ fun FirSession.doUnify(
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeWithParameters is ConeFlexibleType) {
|
|
||||||
return doUnify(
|
|
||||||
originalTypeProjection,
|
|
||||||
typeWithParametersProjection.replaceType(typeWithParameters.lowerBound),
|
|
||||||
targetTypeParameters, result,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeWithParameters is ConeDefinitelyNotNullType) {
|
if (typeWithParameters is ConeDefinitelyNotNullType) {
|
||||||
return doUnify(
|
return doUnify(
|
||||||
originalTypeProjection,
|
originalTypeProjection,
|
||||||
|
|||||||
+29
@@ -0,0 +1,29 @@
|
|||||||
|
// FIR_IDENTICAL
|
||||||
|
|
||||||
|
interface FlameGraphModel<T>
|
||||||
|
|
||||||
|
internal typealias CallUsageNode = CallTreeNode<BaseCallStackElement>
|
||||||
|
|
||||||
|
interface CallTreeNode<out T : Any> : TreeNodeWithParent<CallWithValue<T>>
|
||||||
|
|
||||||
|
interface TreeNodeWithParent<out Data>
|
||||||
|
|
||||||
|
interface CallWithValue<out T : Any>
|
||||||
|
|
||||||
|
abstract class BaseCallStackElement
|
||||||
|
|
||||||
|
open class CallUsageNodeFlameGraphModel<Call : Any> : FlameGraphModel<CallTreeNode<Call>>
|
||||||
|
|
||||||
|
fun foo(model: FlameGraphModel<CallUsageNode>) {
|
||||||
|
// K1: Ok
|
||||||
|
val afterCast = model as CallUsageNodeFlameGraphModel
|
||||||
|
}
|
||||||
|
|
||||||
|
internal typealias CallTreeNodeTypealias<K> = CallTreeNode<K>
|
||||||
|
|
||||||
|
open class CallUsageNodeFlameGraphModelWithTypealiasedSupertypeArgument<Call : Any> : FlameGraphModel<CallTreeNodeTypealias<Call>>
|
||||||
|
|
||||||
|
fun bar(model: FlameGraphModel<CallUsageNode>) {
|
||||||
|
// K1: Ok
|
||||||
|
val afterCast = model as CallUsageNodeFlameGraphModelWithTypealiasedSupertypeArgument
|
||||||
|
}
|
||||||
+51
@@ -0,0 +1,51 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
public fun bar(/*0*/ model: FlameGraphModel<CallUsageNode /* = CallTreeNode<BaseCallStackElement> */>): kotlin.Unit
|
||||||
|
public fun foo(/*0*/ model: FlameGraphModel<CallUsageNode /* = CallTreeNode<BaseCallStackElement> */>): kotlin.Unit
|
||||||
|
|
||||||
|
public abstract class BaseCallStackElement {
|
||||||
|
public constructor BaseCallStackElement()
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface CallTreeNode</*0*/ out T : kotlin.Any> : TreeNodeWithParent<CallWithValue<T>> {
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
|
|
||||||
|
public open class CallUsageNodeFlameGraphModel</*0*/ Call : kotlin.Any> : FlameGraphModel<CallTreeNode<Call>> {
|
||||||
|
public constructor CallUsageNodeFlameGraphModel</*0*/ Call : kotlin.Any>()
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
|
|
||||||
|
public open class CallUsageNodeFlameGraphModelWithTypealiasedSupertypeArgument</*0*/ Call : kotlin.Any> : FlameGraphModel<CallTreeNodeTypealias<Call> /* = CallTreeNode<Call> */> {
|
||||||
|
public constructor CallUsageNodeFlameGraphModelWithTypealiasedSupertypeArgument</*0*/ Call : kotlin.Any>()
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface CallWithValue</*0*/ out T : kotlin.Any> {
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface FlameGraphModel</*0*/ T> {
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface TreeNodeWithParent</*0*/ out Data> {
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
|
internal typealias CallTreeNodeTypealias</*0*/ K> = CallTreeNode<K>
|
||||||
|
internal typealias CallUsageNode = CallTreeNode<BaseCallStackElement>
|
||||||
Generated
+6
@@ -489,6 +489,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
|||||||
runTest("compiler/testData/diagnostics/tests/kt55733.kt");
|
runTest("compiler/testData/diagnostics/tests/kt55733.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kt56612.kt")
|
||||||
|
public void testKt56612() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/kt56612.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("kt56665.kt")
|
@TestMetadata("kt56665.kt")
|
||||||
public void testKt56665() throws Exception {
|
public void testKt56665() throws Exception {
|
||||||
|
|||||||
Reference in New Issue
Block a user