diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerFirTestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerFirTestdataTestGenerated.java index 61cbf15ddd9..044aa9e1f4f 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerFirTestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerFirTestdataTestGenerated.java @@ -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); } + @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 { diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java index 5c61d155333..245c4f6a55a 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java @@ -489,6 +489,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag 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 { diff --git a/compiler/fir/analysis-tests/legacy-fir-tests/tests-gen/org/jetbrains/kotlin/fir/LazyBodyIsNotTouchedTilContractsPhaseTestGenerated.java b/compiler/fir/analysis-tests/legacy-fir-tests/tests-gen/org/jetbrains/kotlin/fir/LazyBodyIsNotTouchedTilContractsPhaseTestGenerated.java index fcddcfa9e36..c64365e3efe 100644 --- a/compiler/fir/analysis-tests/legacy-fir-tests/tests-gen/org/jetbrains/kotlin/fir/LazyBodyIsNotTouchedTilContractsPhaseTestGenerated.java +++ b/compiler/fir/analysis-tests/legacy-fir-tests/tests-gen/org/jetbrains/kotlin/fir/LazyBodyIsNotTouchedTilContractsPhaseTestGenerated.java @@ -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"); diff --git a/compiler/fir/analysis-tests/testData/resolve/types/bareWithDnnArg.fir.txt b/compiler/fir/analysis-tests/testData/resolve/types/bareWithDnnArg.fir.txt new file mode 100644 index 00000000000..6cd02900eb9 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolve/types/bareWithDnnArg.fir.txt @@ -0,0 +1,16 @@ +FILE: main.kt + public abstract interface KotlinCancellablePromise : R|Promise| { + } + public final class D : R|kotlin/Any| { + public constructor(): R|D| { + super() + } + + public final fun foo(x: R|Promise|): R|kotlin/Unit| { + this@R|/D|.R|/D.bar|((R|/x| as R|KotlinCancellablePromise|)) + } + + public final fun bar(x: R|KotlinCancellablePromise|): R|kotlin/Unit| { + } + + } diff --git a/compiler/fir/analysis-tests/testData/resolve/types/bareWithDnnArg.kt b/compiler/fir/analysis-tests/testData/resolve/types/bareWithDnnArg.kt new file mode 100644 index 00000000000..593469f7a05 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolve/types/bareWithDnnArg.kt @@ -0,0 +1,17 @@ +// FIR_IDENTICAL +// SKIP_TXT + +// FILE: Promise.java +public interface Promise {} + +// FILE: main.kt + +interface KotlinCancellablePromise : Promise + +class D { + fun foo(x: Promise) { + bar(x as KotlinCancellablePromise) + } + + fun bar(x: KotlinCancellablePromise) {} +} diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticTestGenerated.java index 9fa693f643c..04a3ec2a06a 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticTestGenerated.java @@ -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 { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticsWithLightTreeTestGenerated.java index 97b09115f88..c3f80db8f47 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticsWithLightTreeTestGenerated.java @@ -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 { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java index 8a0b93dce5d..c24c492b24d 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java @@ -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 { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java index 0f5e52f6578..8a9850d9bea 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java @@ -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 { diff --git a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/TypeUnification.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/TypeUnification.kt index 790a627db90..820479de5fc 100644 --- a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/TypeUnification.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/TypeUnification.kt @@ -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, result: MutableMap, ): 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() @@ -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, diff --git a/compiler/testData/diagnostics/tests/kt56612.kt b/compiler/testData/diagnostics/tests/kt56612.kt new file mode 100644 index 00000000000..6ab9481ba9c --- /dev/null +++ b/compiler/testData/diagnostics/tests/kt56612.kt @@ -0,0 +1,29 @@ +// FIR_IDENTICAL + +interface FlameGraphModel + +internal typealias CallUsageNode = CallTreeNode + +interface CallTreeNode : TreeNodeWithParent> + +interface TreeNodeWithParent + +interface CallWithValue + +abstract class BaseCallStackElement + +open class CallUsageNodeFlameGraphModel : FlameGraphModel> + +fun foo(model: FlameGraphModel) { + // K1: Ok + val afterCast = model as CallUsageNodeFlameGraphModel +} + +internal typealias CallTreeNodeTypealias = CallTreeNode + +open class CallUsageNodeFlameGraphModelWithTypealiasedSupertypeArgument : FlameGraphModel> + +fun bar(model: FlameGraphModel) { + // K1: Ok + val afterCast = model as CallUsageNodeFlameGraphModelWithTypealiasedSupertypeArgument +} diff --git a/compiler/testData/diagnostics/tests/kt56612.txt b/compiler/testData/diagnostics/tests/kt56612.txt new file mode 100644 index 00000000000..98cf098f6a8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/kt56612.txt @@ -0,0 +1,51 @@ +package + +public fun bar(/*0*/ model: FlameGraphModel */>): kotlin.Unit +public fun foo(/*0*/ model: FlameGraphModel */>): 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 : TreeNodeWithParent> { + 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 : FlameGraphModel> { + public constructor CallUsageNodeFlameGraphModel() + 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 : FlameGraphModel /* = CallTreeNode */> { + public constructor CallUsageNodeFlameGraphModelWithTypealiasedSupertypeArgument() + 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 { + 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 { + 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 { + 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 = CallTreeNode +internal typealias CallUsageNode = CallTreeNode diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java index dc0c1e42cfd..d15a367f4ae 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java @@ -489,6 +489,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { 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 {