diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java index 9d0fae35dc9..7f460335834 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java @@ -17917,6 +17917,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/capturingFromArgumentOfFlexibleType.kt"); } + @Test + @TestMetadata("capturingOfDnn.kt") + public void testCapturingOfDnn() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/capturingOfDnn.kt"); + } + @Test @TestMetadata("differentCapturedTypes.kt") public void testDifferentCapturedTypes() throws Exception { @@ -33742,6 +33748,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia runTest("compiler/testData/diagnostics/tests/sealed/DoubleInner.kt"); } + @Test + @TestMetadata("ExhaustiveOnCaptured.kt") + public void testExhaustiveOnCaptured() throws Exception { + runTest("compiler/testData/diagnostics/tests/sealed/ExhaustiveOnCaptured.kt"); + } + @Test @TestMetadata("ExhaustiveOnRoot.kt") public void testExhaustiveOnRoot() throws Exception { diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFirTestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFirTestdataTestGenerated.java index cc2799a7711..1bbcfd0be91 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFirTestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFirTestdataTestGenerated.java @@ -3525,6 +3525,12 @@ public class DiagnosticCompilerTestFirTestdataTestGenerated extends AbstractDiag runTest("compiler/fir/analysis-tests/testData/resolve/inference/nullableIntegerLiteralType.kt"); } + @Test + @TestMetadata("onlyInputTypesCapturedTypeWithRecursiveBounds.kt") + public void testOnlyInputTypesCapturedTypeWithRecursiveBounds() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/inference/onlyInputTypesCapturedTypeWithRecursiveBounds.kt"); + } + @Test @TestMetadata("overloadResolutionByLambdaArgumentType.kt") public void testOverloadResolutionByLambdaArgumentType() throws Exception { diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java index 11d3ab6179e..9be2eda1080 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java @@ -17917,6 +17917,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/capturingFromArgumentOfFlexibleType.kt"); } + @Test + @TestMetadata("capturingOfDnn.kt") + public void testCapturingOfDnn() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/capturingOfDnn.kt"); + } + @Test @TestMetadata("differentCapturedTypes.kt") public void testDifferentCapturedTypes() throws Exception { @@ -33742,6 +33748,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated runTest("compiler/testData/diagnostics/tests/sealed/DoubleInner.kt"); } + @Test + @TestMetadata("ExhaustiveOnCaptured.kt") + public void testExhaustiveOnCaptured() throws Exception { + runTest("compiler/testData/diagnostics/tests/sealed/ExhaustiveOnCaptured.kt"); + } + @Test @TestMetadata("ExhaustiveOnRoot.kt") public void testExhaustiveOnRoot() throws Exception { diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFirTestDataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFirTestDataTestGenerated.java index 94aecb7e227..5880cc27a73 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFirTestDataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFirTestDataTestGenerated.java @@ -3525,6 +3525,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFirTestDataTestGenerated runTest("compiler/fir/analysis-tests/testData/resolve/inference/nullableIntegerLiteralType.kt"); } + @Test + @TestMetadata("onlyInputTypesCapturedTypeWithRecursiveBounds.kt") + public void testOnlyInputTypesCapturedTypeWithRecursiveBounds() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/inference/onlyInputTypesCapturedTypeWithRecursiveBounds.kt"); + } + @Test @TestMetadata("overloadResolutionByLambdaArgumentType.kt") public void testOverloadResolutionByLambdaArgumentType() throws Exception { diff --git a/compiler/fir/analysis-tests/testData/resolve/inference/kt40131.kt b/compiler/fir/analysis-tests/testData/resolve/inference/kt40131.kt index daba2e84409..db42a6c57ea 100644 --- a/compiler/fir/analysis-tests/testData/resolve/inference/kt40131.kt +++ b/compiler/fir/analysis-tests/testData/resolve/inference/kt40131.kt @@ -6,7 +6,7 @@ val KClass.javaImpl: Class get() = null!! val > T.myJava1: Class<*> - get() = ")!>javaImpl + get() = ")!>javaImpl val > T.myJava2: Class get() = ")!>javaImpl diff --git a/compiler/fir/analysis-tests/testData/resolve/inference/onlyInputTypesCapturedTypeWithRecursiveBounds.fir.txt b/compiler/fir/analysis-tests/testData/resolve/inference/onlyInputTypesCapturedTypeWithRecursiveBounds.fir.txt new file mode 100644 index 00000000000..3c0f51a20a4 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolve/inference/onlyInputTypesCapturedTypeWithRecursiveBounds.fir.txt @@ -0,0 +1,75 @@ +FILE: onlyInputTypesCapturedTypeWithRecursiveBounds.kt + public abstract interface I : R|kotlin/Any| { + } + public final enum class MyEnum : R|I|, R|kotlin/Enum| { + private constructor(): R|MyEnum| { + super|>() + } + + public final static enum entry EnumEntry: R|MyEnum| + public final static fun values(): R|kotlin/Array| { + } + + public final static fun valueOf(value: R|kotlin/String|): R|MyEnum| { + } + + public final static val entries: R|kotlin/enums/EnumEntries| + public get(): R|kotlin/enums/EnumEntries| + + } + public open class Foo

|, R|I|> : R|kotlin/Any| { + public constructor

|, R|I|>(data: R|kotlin/collections/Map|): R|Foo

| { + super() + } + + public final val data: R|kotlin/collections/Map| = R|/data| + public get(): R|kotlin/collections/Map| + + } + private final fun test(node: R|Foo<*>|): R|kotlin/Unit| { + R|/node|.R|SubstitutionOverride|>|.R|kotlin/collections/get| & I)|, R|kotlin/Any?|>(Q|MyEnum|.R|/MyEnum.EnumEntry|) + } + public open class FooEnumMap

|, R|I|> : R|kotlin/Any| { + public constructor

|, R|I|>(data: R|java/util/EnumMap|): R|FooEnumMap

| { + super() + } + + public final val data: R|java/util/EnumMap| = R|/data| + public get(): R|java/util/EnumMap| + + } + private final fun test(node: R|FooEnumMap<*>|): R|kotlin/Unit| { + R|/node|.R|SubstitutionOverride|>|.R|kotlin/collections/get| & I), it(kotlin/Enum<*>? & I?)>|, R|kotlin/Any!|>(Q|MyEnum|.R|/MyEnum.EnumEntry|) + } + public open class Foo2

: R|kotlin/Any| { + public constructor

(data: R|kotlin/collections/Map|): R|Foo2

| { + super() + } + + public final val data: R|kotlin/collections/Map| = R|/data| + public get(): R|kotlin/collections/Map| + + } + private final fun test(node: R|Foo2<*>|): R|kotlin/Unit| { + R|/node|.R|SubstitutionOverride|>|.R|kotlin/collections/get|(Q|MyEnum|.R|/MyEnum.EnumEntry|) + } + public abstract interface I2 : R|kotlin/Any| { + } + public final object C : R|I|, R|I2| { + private constructor(): R|C| { + super() + } + + } + public open class Foo3

: R|kotlin/Any| { + public constructor

(data: R|kotlin/collections/Map|): R|Foo3

| { + super() + } + + public final val data: R|kotlin/collections/Map| = R|/data| + public get(): R|kotlin/collections/Map| + + } + public final fun test3(node: R|Foo3<*>|): R|kotlin/Unit| { + R|/node|.R|SubstitutionOverride|>|.R|kotlin/collections/get|(Q|C|) + } diff --git a/compiler/fir/analysis-tests/testData/resolve/inference/onlyInputTypesCapturedTypeWithRecursiveBounds.kt b/compiler/fir/analysis-tests/testData/resolve/inference/onlyInputTypesCapturedTypeWithRecursiveBounds.kt new file mode 100644 index 00000000000..83fcab84804 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolve/inference/onlyInputTypesCapturedTypeWithRecursiveBounds.kt @@ -0,0 +1,37 @@ +// FULL_JDK +// WITH_STDLIB +import java.util.EnumMap + +interface I + +enum class MyEnum : I { + EnumEntry +} + +open class Foo

(val data: Map) where P : Enum

, P : I + +private fun test(node: Foo<*>) { + node.data.get(MyEnum.EnumEntry) +} + +open class FooEnumMap

(val data: EnumMap) where P : Enum

, P : I + +private fun test(node: FooEnumMap<*>) { + node.data.get(MyEnum.EnumEntry) +} + +open class Foo2

(val data: Map) + +private fun test(node: Foo2<*>) { + node.data.get(MyEnum.EnumEntry) +} + +interface I2 + +object C: I, I2 + +open class Foo3

(val data: Map) where P : I, P : I2 + +fun test3(node: Foo3<*>) { + node.data.get(C) +} \ No newline at end of file diff --git a/compiler/fir/analysis-tests/testData/resolve/smartcasts/problems/smartcastToStarProjectedSubclass.kt b/compiler/fir/analysis-tests/testData/resolve/smartcasts/problems/smartcastToStarProjectedSubclass.kt index c011ed9dbcf..8a3537c5f19 100644 --- a/compiler/fir/analysis-tests/testData/resolve/smartcasts/problems/smartcastToStarProjectedSubclass.kt +++ b/compiler/fir/analysis-tests/testData/resolve/smartcasts/problems/smartcastToStarProjectedSubclass.kt @@ -15,7 +15,7 @@ public interface Option { // FILE: test.kt fun test_1(option: Option>?) { if (option is Option.Some<*>) { - val x = ..kotlin.Pair?!")!>option.get().first + val x = ..CapturedType(*)? & kotlin.Pair?")!>option.get().first x.length } } diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeDiagnosticsTestGenerated.java index 468abb6492e..f6b87e11fc0 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeDiagnosticsTestGenerated.java @@ -3525,6 +3525,12 @@ public class FirLightTreeDiagnosticsTestGenerated extends AbstractFirLightTreeDi runTest("compiler/fir/analysis-tests/testData/resolve/inference/nullableIntegerLiteralType.kt"); } + @Test + @TestMetadata("onlyInputTypesCapturedTypeWithRecursiveBounds.kt") + public void testOnlyInputTypesCapturedTypeWithRecursiveBounds() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/inference/onlyInputTypesCapturedTypeWithRecursiveBounds.kt"); + } + @Test @TestMetadata("overloadResolutionByLambdaArgumentType.kt") public void testOverloadResolutionByLambdaArgumentType() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java index cafbec25b47..d83603d20ba 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java @@ -17911,6 +17911,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/capturingFromArgumentOfFlexibleType.kt"); } + @Test + @TestMetadata("capturingOfDnn.kt") + public void testCapturingOfDnn() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/capturingOfDnn.kt"); + } + @Test @TestMetadata("differentCapturedTypes.kt") public void testDifferentCapturedTypes() throws Exception { @@ -31456,6 +31462,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir runTest("compiler/testData/diagnostics/tests/sealed/DoubleInner.kt"); } + @Test + @TestMetadata("ExhaustiveOnCaptured.kt") + public void testExhaustiveOnCaptured() throws Exception { + runTest("compiler/testData/diagnostics/tests/sealed/ExhaustiveOnCaptured.kt"); + } + @Test @TestMetadata("ExhaustiveOnRoot.kt") public void testExhaustiveOnRoot() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiDiagnosticTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiDiagnosticTestGenerated.java index e253cc12fe8..6bd0a51d173 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiDiagnosticTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiDiagnosticTestGenerated.java @@ -3525,6 +3525,12 @@ public class FirPsiDiagnosticTestGenerated extends AbstractFirPsiDiagnosticTest runTest("compiler/fir/analysis-tests/testData/resolve/inference/nullableIntegerLiteralType.kt"); } + @Test + @TestMetadata("onlyInputTypesCapturedTypeWithRecursiveBounds.kt") + public void testOnlyInputTypesCapturedTypeWithRecursiveBounds() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/inference/onlyInputTypesCapturedTypeWithRecursiveBounds.kt"); + } + @Test @TestMetadata("overloadResolutionByLambdaArgumentType.kt") public void testOverloadResolutionByLambdaArgumentType() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java index 7b785be8731..33b0521d099 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java @@ -17917,6 +17917,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/capturingFromArgumentOfFlexibleType.kt"); } + @Test + @TestMetadata("capturingOfDnn.kt") + public void testCapturingOfDnn() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/capturingOfDnn.kt"); + } + @Test @TestMetadata("differentCapturedTypes.kt") public void testDifferentCapturedTypes() throws Exception { @@ -31576,6 +31582,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia runTest("compiler/testData/diagnostics/tests/sealed/DoubleInner.kt"); } + @Test + @TestMetadata("ExhaustiveOnCaptured.kt") + public void testExhaustiveOnCaptured() throws Exception { + runTest("compiler/testData/diagnostics/tests/sealed/ExhaustiveOnCaptured.kt"); + } + @Test @TestMetadata("ExhaustiveOnRoot.kt") public void testExhaustiveOnRoot() throws Exception { diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirHelpers.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirHelpers.kt index 8b2abaebeb4..62744643015 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirHelpers.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirHelpers.kt @@ -46,6 +46,7 @@ import org.jetbrains.kotlin.psi.KtParameter.VAL_VAR_TOKEN_SET import org.jetbrains.kotlin.resolve.AnnotationTargetList import org.jetbrains.kotlin.resolve.AnnotationTargetLists import org.jetbrains.kotlin.types.AbstractTypeChecker +import org.jetbrains.kotlin.types.TypeApproximatorConfiguration import org.jetbrains.kotlin.types.model.KotlinTypeMarker import org.jetbrains.kotlin.types.model.TypeCheckerProviderContext import org.jetbrains.kotlin.util.ImplementationStatus @@ -816,6 +817,13 @@ fun ConeKotlinType.hasDiagnosticKind(kind: DiagnosticKind): Boolean { return this is ConeErrorType && (diagnostic as? ConeSimpleDiagnostic)?.kind == kind } +fun ConeKotlinType.finalApproximationOrSelf(context: CheckerContext): ConeKotlinType { + return context.session.typeApproximator.approximateToSuperType( + this, + TypeApproximatorConfiguration.FinalApproximationAfterResolutionAndInference + ) ?: this +} + fun FirResolvedQualifier.isStandalone( context: CheckerContext, ): Boolean { diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirCastOperatorsChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirCastOperatorsChecker.kt index 0378b9c8302..fa6685da6ed 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirCastOperatorsChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirCastOperatorsChecker.kt @@ -11,6 +11,7 @@ import org.jetbrains.kotlin.diagnostics.reportOn import org.jetbrains.kotlin.fir.analysis.checkers.CastingType import org.jetbrains.kotlin.fir.analysis.checkers.checkCasting import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext +import org.jetbrains.kotlin.fir.analysis.checkers.finalApproximationOrSelf import org.jetbrains.kotlin.fir.analysis.checkers.isCastErased import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors import org.jetbrains.kotlin.fir.expressions.FirOperation @@ -24,9 +25,9 @@ object FirCastOperatorsChecker : FirTypeOperatorCallChecker() { override fun check(expression: FirTypeOperatorCall, context: CheckerContext, reporter: DiagnosticReporter) { val session = context.session val firstArgument = expression.argumentList.arguments[0] - val actualType = firstArgument.unwrapSmartcastExpression().resolvedType.fullyExpandedType(session) + val actualType = firstArgument.unwrapSmartcastExpression().resolvedType.fullyExpandedType(session).finalApproximationOrSelf(context) val conversionTypeRef = expression.conversionTypeRef - val targetType = conversionTypeRef.coneType.fullyExpandedType(session) + val targetType = conversionTypeRef.coneType.fullyExpandedType(session).finalApproximationOrSelf(context) if (expression.operation in FirOperation.TYPES && targetType is ConeDynamicType) { reporter.reportOn(conversionTypeRef.source, FirErrors.DYNAMIC_NOT_ALLOWED, context) diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirEqualityCompatibilityChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirEqualityCompatibilityChecker.kt index 6cf42530f5f..0c782c2c57f 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirEqualityCompatibilityChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirEqualityCompatibilityChecker.kt @@ -14,6 +14,7 @@ import org.jetbrains.kotlin.diagnostics.reportOn import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.collectUpperBounds import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext +import org.jetbrains.kotlin.fir.analysis.checkers.finalApproximationOrSelf import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors import org.jetbrains.kotlin.fir.declarations.utils.isEnumClass import org.jetbrains.kotlin.fir.declarations.utils.isFinal @@ -383,7 +384,10 @@ private val FirExpression.mostOriginalTypeIfSmartCast: ConeKotlinType private fun FirExpression.toArgumentInfo(context: CheckerContext) = ArgumentInfo( - this, resolvedType, mostOriginalTypeIfSmartCast.fullyExpandedType(context.session), context.session, + this, + userType = resolvedType.finalApproximationOrSelf(context), + originalType = mostOriginalTypeIfSmartCast.fullyExpandedType(context.session).finalApproximationOrSelf(context), + context.session, ) /** diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/PrimitiveComparison.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/PrimitiveComparison.kt index 3aa00e13379..c898149cd77 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/PrimitiveComparison.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/PrimitiveComparison.kt @@ -24,9 +24,11 @@ val FirComparisonExpression.left: FirExpression val FirComparisonExpression.right: FirExpression get() = compareToCall.arguments.getOrNull(0) ?: error("There should be a first arg for ${compareToCall.render()}") +context(Fir2IrComponents) fun FirComparisonExpression.inferPrimitiveNumericComparisonInfo(): PrimitiveConeNumericComparisonInfo? = inferPrimitiveNumericComparisonInfo(left, right) +context(Fir2IrComponents) fun inferPrimitiveNumericComparisonInfo(left: FirExpression, right: FirExpression): PrimitiveConeNumericComparisonInfo? { val leftType = left.resolvedType val rightType = right.resolvedType @@ -57,6 +59,7 @@ private fun ConeClassLikeType.promoteIntegerTypeToIntIfRequired(): ConeClassLike else -> error("Primitive number type expected: $this") } +context(Fir2IrComponents) private fun ConeKotlinType.getPrimitiveTypeOrSupertype(): ConeClassLikeType? = when { this is ConeTypeParameterType -> @@ -67,6 +70,8 @@ private fun ConeKotlinType.getPrimitiveTypeOrSupertype(): ConeClassLikeType? = this this is ConeFlexibleType -> this.lowerBound.getPrimitiveTypeOrSupertype() + this is ConeCapturedType -> + this.approximateForIrOrSelf().getPrimitiveTypeOrSupertype() else -> null } diff --git a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/ConeInferenceContext.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/ConeInferenceContext.kt index 33b4d98c7ae..52a7b21db90 100644 --- a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/ConeInferenceContext.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/ConeInferenceContext.kt @@ -343,6 +343,13 @@ interface ConeInferenceContext : TypeSystemInferenceExtensionContext, ConeTypeCo return isProjectionNotNull } + override fun CapturedTypeMarker.hasRawSuperType(): Boolean { + require(this is ConeCapturedType) + return constructor.supertypes?.any { superType -> + superType.contains { it is ConeKotlinType && it.isRaw() } + } == true + } + override fun DefinitelyNotNullTypeMarker.original(): SimpleTypeMarker { require(this is ConeDefinitelyNotNullType) return this.original diff --git a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/TypeUtils.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/TypeUtils.kt index f145dc613d9..a9f3ee5bbf7 100644 --- a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/TypeUtils.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/TypeUtils.kt @@ -425,8 +425,26 @@ fun ConeTypeContext.captureArguments(type: ConeKotlinType, status: CaptureStatus } require(newArgument is ConeCapturedType) - @Suppress("UNCHECKED_CAST") - newArgument.constructor.supertypes = upperBounds as List + + newArgument.constructor.supertypes = if (status == CaptureStatus.FROM_EXPRESSION) { + // By intersecting the bounds and the projection type, we eliminate "redundant" super types. + // Redundant is defined by the implementation of the type intersector, + // e.g., at the moment of writing the intersection of Foo and Foo was Foo. + // Note, it's not just an optimization, but actually influences behavior because the nullability can change like in the + // example above. + // We only run it for status == CaptureStatus.FROM_EXPRESSION to prevent infinite loops with recursive types because + // during intersection AbstractTypeChecker is called which in turn can capture super types with status + // CaptureStatus.FOR_SUBTYPING. + val intersectedUpperBounds = intersectTypes(upperBounds) + if (intersectedUpperBounds is ConeIntersectionType) { + intersectedUpperBounds.intersectedTypes.toList() + } else { + listOf(intersectedUpperBounds) + } + } else { + @Suppress("UNCHECKED_CAST") + upperBounds as List + } } return newArguments } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/ConstraintSystemCompleter.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/ConstraintSystemCompleter.kt index 9802589f9c4..b344c99ed1e 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/ConstraintSystemCompleter.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/ConstraintSystemCompleter.kt @@ -416,8 +416,21 @@ class ConstraintSystemCompleter(components: BodyResolveComponents, private val c variableWithConstraints, TypeVariableDirectionCalculator.ResolveDirection.UNKNOWN ) + + val resultTypeForOnlyInputTypes = + if (with(ConeConstraintSystemUtilContext) { variableWithConstraints.typeVariable.hasOnlyInputTypesAttribute() }) { + inferenceComponents.resultTypeResolver.findResultType( + c, + variableWithConstraints, + TypeVariableDirectionCalculator.ResolveDirection.UNKNOWN, + isForOnlyInputTypes = true + ) + } else { + resultType + } + val variable = variableWithConstraints.typeVariable - c.fixVariable(variable, resultType, ConeFixVariableConstraintPosition(variable)) + c.fixVariable(variable, resultType, ConeFixVariableConstraintPosition(variable), resultTypeForOnlyInputTypes) } companion object { diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/FirCallCompleter.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/FirCallCompleter.kt index 7bfff364605..a731b8a0ce4 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/FirCallCompleter.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/FirCallCompleter.kt @@ -389,7 +389,7 @@ class FirCallCompleter( } return session.typeApproximator.approximateToSuperType( - this, TypeApproximatorConfiguration.FinalApproximationAfterResolutionAndInference + this, TypeApproximatorConfiguration.IntermediateApproximationToSupertypeAfterCompletionInK2 ) ?: this } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirCallCompletionResultsWriterTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirCallCompletionResultsWriterTransformer.kt index 8b2c90976f8..fabbe419ac9 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirCallCompletionResultsWriterTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirCallCompletionResultsWriterTransformer.kt @@ -495,7 +495,8 @@ class FirCallCompletionResultsWriterTransformer( val initialType = candidate.substitutor.substituteOrSelf(type) val substitutedType = finallySubstituteOrNull(initialType) val finalType = typeApproximator.approximateToSuperType( - type = substitutedType ?: initialType, TypeApproximatorConfiguration.FinalApproximationAfterResolutionAndInference, + type = substitutedType ?: initialType, + TypeApproximatorConfiguration.IntermediateApproximationToSupertypeAfterCompletionInK2, ) ?: substitutedType // This is probably a temporary hack, but it seems necessary because elvis has that attribute and it may leak further like @@ -968,7 +969,7 @@ class FirCallCompletionResultsWriterTransformer( arrayLiteral.transformChildren(this, expectedArrayElementType?.toExpectedType()) val arrayElementType = session.typeContext.commonSuperTypeOrNull(arrayLiteral.arguments.map { it.resolvedType })?.let { - typeApproximator.approximateToSuperType(it, TypeApproximatorConfiguration.FinalApproximationAfterResolutionAndInference) + typeApproximator.approximateToSuperType(it, TypeApproximatorConfiguration.IntermediateApproximationToSupertypeAfterCompletionInK2) ?: it } ?: expectedArrayElementType ?: session.builtinTypes.nullableAnyType.type arrayLiteral.resultType = diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirWhenExhaustivenessTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirWhenExhaustivenessTransformer.kt index 3fb6e8bb149..43b3704aaae 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirWhenExhaustivenessTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirWhenExhaustivenessTransformer.kt @@ -33,6 +33,7 @@ import org.jetbrains.kotlin.fir.types.* import org.jetbrains.kotlin.fir.visitors.FirTransformer import org.jetbrains.kotlin.fir.visitors.FirVisitor import org.jetbrains.kotlin.name.StandardClassIds +import org.jetbrains.kotlin.types.TypeApproximatorConfiguration class FirWhenExhaustivenessTransformer(private val bodyResolveComponents: BodyResolveComponents) : FirTransformer() { companion object { @@ -119,7 +120,9 @@ class FirWhenExhaustivenessTransformer(private val bodyResolveComponents: BodyRe } val session = bodyResolveComponents.session - val subjectType = getSubjectType(session, whenExpression) ?: run { + val subjectType = getSubjectType(session, whenExpression)?.let { + session.typeApproximator.approximateToSuperType(it, TypeApproximatorConfiguration.FinalApproximationAfterResolutionAndInference) ?: it + } ?: run { whenExpression.replaceExhaustivenessStatus(ExhaustivenessStatus.NotExhaustive.NO_ELSE_BRANCH) return } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirExpressionsResolveTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirExpressionsResolveTransformer.kt index d2f2622ae34..dd10bdfae75 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirExpressionsResolveTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirExpressionsResolveTransformer.kt @@ -1717,7 +1717,7 @@ open class FirExpressionsResolveTransformer(transformer: FirAbstractBodyResolveT ) } else { session.typeApproximator.approximateToSuperType( - typeFromCallee.type, TypeApproximatorConfiguration.FinalApproximationAfterResolutionAndInference + typeFromCallee.type, TypeApproximatorConfiguration.IntermediateApproximationToSupertypeAfterCompletionInK2 ) } ?: typeFromCallee.type } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/bareTypes.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/bareTypes.kt index 8f7f351b606..e0f2b20d2e7 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/bareTypes.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/bareTypes.kt @@ -18,6 +18,7 @@ import org.jetbrains.kotlin.fir.symbols.impl.FirTypeParameterSymbol import org.jetbrains.kotlin.fir.symbols.lazyResolveToPhase import org.jetbrains.kotlin.fir.types.* import org.jetbrains.kotlin.types.AbstractTypeChecker +import org.jetbrains.kotlin.types.TypeApproximatorConfiguration fun BodyResolveComponents.computeRepresentativeTypeForBareType(type: ConeClassLikeType, originalType: ConeKotlinType): ConeKotlinType? { originalType.lowerBoundIfFlexible().fullyExpandedType(session).let { @@ -30,6 +31,13 @@ fun BodyResolveComponents.computeRepresentativeTypeForBareType(type: ConeClassLi return candidatesFromIntersectedTypes.firstOrNull() } + session.typeApproximator.approximateToSuperType( + originalType, + TypeApproximatorConfiguration.FinalApproximationAfterResolutionAndInference + )?.let { + return computeRepresentativeTypeForBareType(type, it) + } + val originalClassLookupTag = (originalType as? ConeClassLikeType)?.fullyExpandedType(session)?.lookupTag ?: return null val castTypeAlias = type.lookupTag.toSymbol(session)?.fir as? FirTypeAlias diff --git a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintSystemCompletionContext.kt b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintSystemCompletionContext.kt index 9adfaff6926..605eba48e14 100644 --- a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintSystemCompletionContext.kt +++ b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintSystemCompletionContext.kt @@ -32,7 +32,12 @@ abstract class ConstraintSystemCompletionContext : VariableFixationFinder.Contex // mutable operations abstract fun addError(error: ConstraintSystemError) - abstract fun fixVariable(variable: TypeVariableMarker, resultType: KotlinTypeMarker, position: FixVariableConstraintPosition<*>) + abstract fun fixVariable( + variable: TypeVariableMarker, + resultType: KotlinTypeMarker, + position: FixVariableConstraintPosition<*>, + resultTypeForOnlyInputTypes: KotlinTypeMarker = resultType + ) abstract fun couldBeResolvedWithUnrestrictedBuilderInference(): Boolean abstract fun resolveForkPointsConstraints() diff --git a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/ResultTypeResolver.kt b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/ResultTypeResolver.kt index ebef7dc5969..8780ff9f3cc 100644 --- a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/ResultTypeResolver.kt +++ b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/ResultTypeResolver.kt @@ -58,8 +58,8 @@ class ResultTypeResolver( return if (direction == ResolveDirection.TO_SUBTYPE) nothingType() else nullableAnyType() } - fun findResultType(c: Context, variableWithConstraints: VariableWithConstraints, direction: ResolveDirection): KotlinTypeMarker { - findResultTypeOrNull(c, variableWithConstraints, direction)?.let { return it } + fun findResultType(c: Context, variableWithConstraints: VariableWithConstraints, direction: ResolveDirection, isForOnlyInputTypes: Boolean = false): KotlinTypeMarker { + findResultTypeOrNull(c, variableWithConstraints, direction, isForOnlyInputTypes)?.let { return it } // no proper constraints return c.getDefaultType(direction, variableWithConstraints.constraints, variableWithConstraints.typeVariable) @@ -68,7 +68,8 @@ class ResultTypeResolver( fun findResultTypeOrNull( c: Context, variableWithConstraints: VariableWithConstraints, - direction: ResolveDirection + direction: ResolveDirection, + isForOnlyInputTypes: Boolean = false, ): KotlinTypeMarker? { val resultTypeFromEqualConstraint = findResultIfThereIsEqualsConstraint(c, variableWithConstraints) if (resultTypeFromEqualConstraint != null) { @@ -83,7 +84,7 @@ class ResultTypeResolver( } } - val subType = c.findSubType(variableWithConstraints) + val subType = c.findSubType(variableWithConstraints, isForOnlyInputTypes) // Super type should be the most flexible, sub type should be the least one val superType = c.findSuperType(variableWithConstraints).makeFlexibleIfNecessary(c, variableWithConstraints.constraints) @@ -208,8 +209,8 @@ class ResultTypeResolver( return constraints.singleOrNull { it.kind.isLower() }?.isNullabilityConstraint ?: false } - private fun Context.findSubType(variableWithConstraints: VariableWithConstraints): KotlinTypeMarker? { - val lowerConstraintTypes = prepareLowerConstraints(variableWithConstraints.constraints) + private fun Context.findSubType(variableWithConstraints: VariableWithConstraints, isForOnlyInputTypes: Boolean): KotlinTypeMarker? { + val lowerConstraintTypes = prepareLowerConstraints(variableWithConstraints.constraints, isForOnlyInputTypes) if (lowerConstraintTypes.isNotEmpty()) { val types = sinkIntegerLiteralTypes(lowerConstraintTypes) @@ -259,7 +260,7 @@ class ResultTypeResolver( private fun Context.computeCommonSuperType(types: List): KotlinTypeMarker = with(NewCommonSuperTypeCalculator) { commonSuperType(types) } - private fun Context.prepareLowerConstraints(constraints: List): List { + private fun Context.prepareLowerConstraints(constraints: List, isForOnlyInputTypes: Boolean): List { var atLeastOneProper = false var atLeastOneNonProper = false @@ -268,7 +269,15 @@ class ResultTypeResolver( for (constraint in constraints) { if (constraint.kind != ConstraintKind.LOWER) continue - val type = constraint.type + var type = constraint.type + + // The call to commonSuperTypes will replace arguments that have recursive supertypes with star projections, + // which will lead to a different resulting type than approximating it first. + // This breaks the @OnlyInputTypes check for captured types with recursive super types. + if (isForOnlyInputTypes && isK2 && hasRecursiveTypeParametersWithGivenSelfType(type.typeConstructor())) { + type = typeApproximator.approximateToSuperType(type, TypeApproximatorConfiguration.InternalTypesApproximation) ?: type + } + lowerConstraintTypes.add(type) if (isProperTypeForFixation(type)) { diff --git a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/model/NewConstraintSystemImpl.kt b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/model/NewConstraintSystemImpl.kt index a8b8e83f8f8..a27f9c56136 100644 --- a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/model/NewConstraintSystemImpl.kt +++ b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/model/NewConstraintSystemImpl.kt @@ -567,6 +567,7 @@ class NewConstraintSystemImpl( variable: TypeVariableMarker, resultType: KotlinTypeMarker, position: FixVariableConstraintPosition<*>, + resultTypeForOnlyInputTypes: KotlinTypeMarker, ) = with(utilContext) { checkState(State.BUILDING, State.COMPLETION) @@ -593,7 +594,7 @@ class NewConstraintSystemImpl( // Substitute freshly fixed type variable into missed constraints substituteMissedConstraints() - postponeOnlyInputTypesCheck(variableWithConstraints, resultType) + postponeOnlyInputTypesCheck(variableWithConstraints, resultTypeForOnlyInputTypes) doPostponedComputationsIfAllVariablesAreFixed() } diff --git a/compiler/resolution.common/src/org/jetbrains/kotlin/types/TypeApproximatorConfiguration.kt b/compiler/resolution.common/src/org/jetbrains/kotlin/types/TypeApproximatorConfiguration.kt index 8bea6625a4c..a7961edf068 100644 --- a/compiler/resolution.common/src/org/jetbrains/kotlin/types/TypeApproximatorConfiguration.kt +++ b/compiler/resolution.common/src/org/jetbrains/kotlin/types/TypeApproximatorConfiguration.kt @@ -113,6 +113,24 @@ open class TypeApproximatorConfiguration { override val convertToNonRawVersionAfterApproximationInK2: Boolean get() = true } + object IntermediateApproximationToSupertypeAfterCompletionInK2 : + AbstractCapturedTypesApproximation(null) { + override val integerLiteralConstantType: Boolean get() = true + override val integerConstantOperatorType: Boolean get() = true + override val intersectionTypesInContravariantPositions: Boolean get() = true + + override val convertToNonRawVersionAfterApproximationInK2: Boolean get() = true + + override fun capturedType(ctx: TypeSystemInferenceExtensionContext, type: CapturedTypeMarker): Boolean { + /** + * Only approximate captured types when they contain a raw supertype. + * This is an awful hack required to keep K1 compatibility. + * See [convertToNonRawVersionAfterApproximationInK2]. + */ + return type.captureStatus(ctx) == CaptureStatus.FROM_EXPRESSION && with(ctx) { type.hasRawSuperType() } + } + } + object TypeArgumentApproximation : AbstractCapturedTypesApproximation(null) { override val integerLiteralConstantType: Boolean get() = true override val integerConstantOperatorType: Boolean get() = true diff --git a/compiler/testData/codegen/box/builderInference/issues/kt52838b.kt b/compiler/testData/codegen/box/builderInference/issues/kt52838b.kt index 6479d58fe01..d447b632290 100644 --- a/compiler/testData/codegen/box/builderInference/issues/kt52838b.kt +++ b/compiler/testData/codegen/box/builderInference/issues/kt52838b.kt @@ -2,9 +2,6 @@ // ISSUE: KT-52838 // IGNORE_LIGHT_ANALYSIS -// IGNORE_BACKEND_K2: WASM -// REASON: That still doesn't work properly with PCLA, but accidentally don't fails for other tests but WASM -// (see KT-52838 for tracking and same-named diagnostic test) fun box(): String { build { diff --git a/compiler/testData/codegen/box/builderInference/issues/kt52838c.kt b/compiler/testData/codegen/box/builderInference/issues/kt52838c.kt index ce28e2eb47c..56f6d05049e 100644 --- a/compiler/testData/codegen/box/builderInference/issues/kt52838c.kt +++ b/compiler/testData/codegen/box/builderInference/issues/kt52838c.kt @@ -1,10 +1,6 @@ // ISSUE: KT-52838 // JVM_ABI_K1_K2_DIFF: KT-64738 -// IGNORE_BACKEND_K2: WASM -// REASON: That still doesn't work properly with PCLA, but accidentally don't fails for other tests but WASM -// (see KT-52838 for tracking and same-named diagnostic test) - fun box(): String { build { this as DerivedBuildee<*> diff --git a/compiler/testData/codegen/box/sam/contravariantIntersectionType.jvm_abi.txt b/compiler/testData/codegen/box/sam/contravariantIntersectionType.jvm_abi.txt index 40ebb888d72..8925ee1bf6c 100644 --- a/compiler/testData/codegen/box/sam/contravariantIntersectionType.jvm_abi.txt +++ b/compiler/testData/codegen/box/sam/contravariantIntersectionType.jvm_abi.txt @@ -1,3 +1,9 @@ MODULE main Missing in K2 TestKt$example$2.class + CLASS TestKt$example$1.class + Property: class.signature + K1 + Lkotlin/jvm/internal/Lambda;Lkotlin/jvm/functions/Function1<*Lkotlin/Unit;>; + K2 + NULL diff --git a/compiler/testData/codegen/box/sam/kt11696.jvm_abi.txt b/compiler/testData/codegen/box/sam/kt11696.jvm_abi.txt new file mode 100644 index 00000000000..353f81c516b --- /dev/null +++ b/compiler/testData/codegen/box/sam/kt11696.jvm_abi.txt @@ -0,0 +1,33 @@ +MODULE main + Missing in K1 + _1Kt$sam$Consumer$0.class + CLASS User$use$1.class + Property: class.signature + K1 + Ljava/lang/Object;LConsumer; + K2 + NULL + Property: class.superClassInternalName + K1 + java/lang/Object + K2 + kotlin/jvm/internal/Lambda + Property: class.superInterfaces + K1 + [Consumer] + K2 + [kotlin/jvm/functions/Function1] + K1 + consume(Ljava/lang/Object;)V [public, final] + K2 + --- + K1 + --- + K2 + invoke(Ljava/lang/Object;)V [public, final] + FIELD INSTANCE:LUser$use$1; + Property: field.signature + K1 + LUser$use$1; + K2 + NULL diff --git a/compiler/testData/codegen/box/sam/kt11696.kt b/compiler/testData/codegen/box/sam/kt11696.kt index d5527be4d4a..44a31f5d26b 100644 --- a/compiler/testData/codegen/box/sam/kt11696.kt +++ b/compiler/testData/codegen/box/sam/kt11696.kt @@ -3,6 +3,7 @@ // SAM_CONVERSIONS: CLASS // ^ test checks reflection for synthetic classes // MODULE: lib +// JVM_ABI_K1_K2_DIFF: KT-64954 // FILE: Promise.java import org.jetbrains.annotations.NotNull; diff --git a/compiler/testData/codegen/box/vararg/kt52146_samWithSelfTypeAndStarProjection.jvm_abi.txt b/compiler/testData/codegen/box/vararg/kt52146_samWithSelfTypeAndStarProjection.jvm_abi.txt new file mode 100644 index 00000000000..ee02b56f5b5 --- /dev/null +++ b/compiler/testData/codegen/box/vararg/kt52146_samWithSelfTypeAndStarProjection.jvm_abi.txt @@ -0,0 +1,3 @@ +MODULE main + Missing in K1 + BoxKt$test$2.class diff --git a/compiler/testData/codegen/box/vararg/kt52146_samWithSelfTypeAndStarProjection.kt b/compiler/testData/codegen/box/vararg/kt52146_samWithSelfTypeAndStarProjection.kt index a9ee568485e..92ee9a7c2c1 100644 --- a/compiler/testData/codegen/box/vararg/kt52146_samWithSelfTypeAndStarProjection.kt +++ b/compiler/testData/codegen/box/vararg/kt52146_samWithSelfTypeAndStarProjection.kt @@ -1,6 +1,7 @@ // TARGET_BACKEND: JVM // FULL_JDK // JVM_TARGET: 1.8 +// JVM_ABI_K1_K2_DIFF: KT-64954 // FILE: J.java import java.util.function.*; diff --git a/compiler/testData/diagnostics/tests/capturedTypesSubtyping.fir.kt b/compiler/testData/diagnostics/tests/capturedTypesSubtyping.fir.kt index a76932177bb..b7b1654dd47 100644 --- a/compiler/testData/diagnostics/tests/capturedTypesSubtyping.fir.kt +++ b/compiler/testData/diagnostics/tests/capturedTypesSubtyping.fir.kt @@ -1,8 +1,8 @@ // ISSUE: KT-62959 fun bar(x: Inv) { - x.foo { it } - x.bar { it.e() } + x.foo { it } + x.bar { it.e() } } interface Inv { diff --git a/compiler/testData/diagnostics/tests/generics/approximationOfInProjection.fir.kt b/compiler/testData/diagnostics/tests/generics/approximationOfInProjection.fir.kt index 50df2e7848f..9810e256f29 100644 --- a/compiler/testData/diagnostics/tests/generics/approximationOfInProjection.fir.kt +++ b/compiler/testData/diagnostics/tests/generics/approximationOfInProjection.fir.kt @@ -5,10 +5,10 @@ class Bound(val value: T) fun test_1() { val b: Bound = Bound(1) - val vl: Number = b.value + val vl: Number = b.value } fun test_2() { val b: Bound<*> = Bound(1) - val vl: Number = b.value + val vl: Number = b.value } diff --git a/compiler/testData/diagnostics/tests/inference/capturedTypes/approximationLeavesNonTrivialLowerBound.fir.kt b/compiler/testData/diagnostics/tests/inference/capturedTypes/approximationLeavesNonTrivialLowerBound.fir.kt new file mode 100644 index 00000000000..d29ef49b5e1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/capturedTypes/approximationLeavesNonTrivialLowerBound.fir.kt @@ -0,0 +1,18 @@ +interface Inv + +fun id(i: Inv): Inv = i + +fun foo1(x: Inv) { + val y = ")!>id(x) // Should return Inv + bar1(y) +} + +fun bar1(i: Inv) {} + +fun foo2(x: Inv) { + // Inv is OK here, because it's still a subtype of Inv + val y = ")!>id(x) + bar2(y) +} + +fun bar2(i: Inv) {} diff --git a/compiler/testData/diagnostics/tests/inference/capturedTypes/approximationLeavesNonTrivialLowerBound.kt b/compiler/testData/diagnostics/tests/inference/capturedTypes/approximationLeavesNonTrivialLowerBound.kt index 0c053b04de9..51fd1a7d8c7 100644 --- a/compiler/testData/diagnostics/tests/inference/capturedTypes/approximationLeavesNonTrivialLowerBound.kt +++ b/compiler/testData/diagnostics/tests/inference/capturedTypes/approximationLeavesNonTrivialLowerBound.kt @@ -1,4 +1,3 @@ -// FIR_IDENTICAL interface Inv fun id(i: Inv): Inv = i diff --git a/compiler/testData/diagnostics/tests/inference/capturedTypes/captureFromNullableTypeInScopeAny.fir.kt b/compiler/testData/diagnostics/tests/inference/capturedTypes/captureFromNullableTypeInScopeAny.fir.kt new file mode 100644 index 00000000000..dac4e5d4ff8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/capturedTypes/captureFromNullableTypeInScopeAny.fir.kt @@ -0,0 +1,13 @@ +// ISSUE: KT-57958 + +fun ListVM<*>.foo() { + val currentItem1: MutableProperty = ")!>currentItem +} + +interface MutableProperty { + var value: T +} + +interface ListVM { + val currentItem: MutableProperty +} diff --git a/compiler/testData/diagnostics/tests/inference/capturedTypes/captureFromNullableTypeInScopeAny.kt b/compiler/testData/diagnostics/tests/inference/capturedTypes/captureFromNullableTypeInScopeAny.kt index 753166b9168..a8352a269b2 100644 --- a/compiler/testData/diagnostics/tests/inference/capturedTypes/captureFromNullableTypeInScopeAny.kt +++ b/compiler/testData/diagnostics/tests/inference/capturedTypes/captureFromNullableTypeInScopeAny.kt @@ -1,4 +1,3 @@ -// FIR_IDENTICAL // ISSUE: KT-57958 fun ListVM<*>.foo() { diff --git a/compiler/testData/diagnostics/tests/inference/capturedTypes/capturedTypesSubstitutionIntoAbbreviation.fir.kt b/compiler/testData/diagnostics/tests/inference/capturedTypes/capturedTypesSubstitutionIntoAbbreviation.fir.kt index 80876c7b852..b767d21ee42 100644 --- a/compiler/testData/diagnostics/tests/inference/capturedTypes/capturedTypesSubstitutionIntoAbbreviation.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/capturedTypes/capturedTypesSubstitutionIntoAbbreviation.fir.kt @@ -20,11 +20,11 @@ fun getTag7(): Tag7<*> = Tag7 { } fun getTag8(): Tag8<*> = Tag8 { 1 } fun main() { - ")!>getTag().action - ")!>getTag2().action - ")!>getTag3().action - ")!>getTag4().action - ")!>getTag5().action + ")!>getTag().action + ")!>getTag2().action + ")!>getTag3().action + ")!>getTag4().action + ")!>getTag5().action ")!>getTag6().action ")!>getTag7().action ")!>getTag8().action diff --git a/compiler/testData/diagnostics/tests/inference/capturedTypes/capturingOfDnn.kt b/compiler/testData/diagnostics/tests/inference/capturedTypes/capturingOfDnn.kt new file mode 100644 index 00000000000..eaa1a964870 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/capturedTypes/capturingOfDnn.kt @@ -0,0 +1,16 @@ +// FIR_IDENTICAL + +// FILE: Inlay.java +public interface Inlay { + @org.jetbrains.annotations.NotNull T getRenderer(); +} + +// FILE: test.kt +interface EditorCustomElementRenderer +interface PresentationContainerRenderer : EditorCustomElementRenderer + +fun test(inlay: Inlay>) { + inlay.renderer.addOrUpdate() +} + +fun PresentationContainerRenderer.addOrUpdate() {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/capturedTypes/kt46727.fir.kt b/compiler/testData/diagnostics/tests/inference/capturedTypes/kt46727.fir.kt index ac1c9d47ce0..9ee4e256d3f 100644 --- a/compiler/testData/diagnostics/tests/inference/capturedTypes/kt46727.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/capturedTypes/kt46727.fir.kt @@ -44,7 +44,7 @@ public class Bar { fun takeStarBar(x: Bar<*>) { x.value = "test" - x.value += "test" + x.value += "test" } fun main2() { @@ -58,7 +58,7 @@ fun main2() { fun takeStarFoo2(x: Foo2<*>) { x.value = "test" - x.value += "test" + x.value += "test" } fun main3() { @@ -75,7 +75,7 @@ public class Bar2 { fun takeStarBar2(x: Bar2<*>) { x.value = "test" - x.value += "test" + x.value += "test" } fun main4() { @@ -89,7 +89,7 @@ fun main4() { fun takeStarFoo3(x: Foo3<*>) { x.value = "test" - x.value += "test" + x.value += "test" } fun main5() { @@ -107,7 +107,7 @@ class Bar3 { fun takeStarBar3(x: Bar3<*>) { x.value = "test" - x.value += "test" + x.value += "test" } fun main6() { diff --git a/compiler/testData/diagnostics/tests/inference/capturedTypes/kt46727Warnings.fir.kt b/compiler/testData/diagnostics/tests/inference/capturedTypes/kt46727Warnings.fir.kt index b8c2d5ef661..9185cf80935 100644 --- a/compiler/testData/diagnostics/tests/inference/capturedTypes/kt46727Warnings.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/capturedTypes/kt46727Warnings.fir.kt @@ -44,7 +44,7 @@ public class Bar { fun takeStarBar(x: Bar<*>) { x.value = "test" - x.value += "test" + x.value += "test" } fun main2() { @@ -58,7 +58,7 @@ fun main2() { fun takeStarFoo2(x: Foo2<*>) { x.value = "test" - x.value += "test" + x.value += "test" } fun main3() { @@ -75,7 +75,7 @@ public class Bar2 { fun takeStarBar2(x: Bar2<*>) { x.value = "test" - x.value += "test" + x.value += "test" } fun main4() { @@ -89,7 +89,7 @@ fun main4() { fun takeStarFoo3(x: Foo3<*>) { x.value = "test" - x.value += "test" + x.value += "test" } fun main5() { @@ -107,7 +107,7 @@ class Bar3 { fun takeStarBar3(x: Bar3<*>) { x.value = "test" - x.value += "test" + x.value += "test" } fun main6() { diff --git a/compiler/testData/diagnostics/tests/inference/capturedTypes/memberScopeOfCaptured.fir.kt b/compiler/testData/diagnostics/tests/inference/capturedTypes/memberScopeOfCaptured.fir.kt new file mode 100644 index 00000000000..977e52e5eb0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/capturedTypes/memberScopeOfCaptured.fir.kt @@ -0,0 +1,13 @@ +// !CHECK_TYPE + +class A { + fun foo(): T = null!! +} + +fun A.bar(): A = this + +fun baz(x: A) { + x.bar() checkType { _>() } + x.bar().foo() checkType { _() } // See KT-10448 + x.bar().foo() checkType { _() } // Inference change in K2 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/capturedTypes/memberScopeOfCaptured.kt b/compiler/testData/diagnostics/tests/inference/capturedTypes/memberScopeOfCaptured.kt index 0e4e5cce82a..162ecf7401e 100644 --- a/compiler/testData/diagnostics/tests/inference/capturedTypes/memberScopeOfCaptured.kt +++ b/compiler/testData/diagnostics/tests/inference/capturedTypes/memberScopeOfCaptured.kt @@ -1,4 +1,3 @@ -// FIR_IDENTICAL // !CHECK_TYPE class A { @@ -9,5 +8,6 @@ fun A.bar(): A = this fun baz(x: A) { x.bar() checkType { _>() } - x.bar().foo() checkType { _() } // See KT-10448 + x.bar().foo() checkType { _() } // See KT-10448 + x.bar().foo() checkType { _() } // Inference change in K2 } diff --git a/compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes/enabledInferenceOnSelfTypes/writerAppenderExampleRecursive.fir.kt b/compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes/enabledInferenceOnSelfTypes/writerAppenderExampleRecursive.fir.kt index 069119355b0..11385017a5f 100644 --- a/compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes/enabledInferenceOnSelfTypes/writerAppenderExampleRecursive.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/recursiveTypes/selfTypes/enabledInferenceOnSelfTypes/writerAppenderExampleRecursive.fir.kt @@ -19,17 +19,17 @@ public class JavaWriterAppender { // FILE: main.kt fun test() { - ")!>WriterAppender.newBuilder() - >")!>WriterAppender.Builder1() + WriterAppender.newBuilder() + ")!>WriterAppender.Builder1() - & WriterAppender.Builder2<*>")!>WriterAppender.intersectTwoSelfTypes() + WriterAppender.intersectTwoSelfTypes() } fun testJava(appender: JavaWriterAppender) { - ..JavaWriterAppender.Builder1<*>?!")!>appender.newBuilder() - ..JavaWriterAppender.Builder1<*>?!>")!>appender.Builder1() + appender.newBuilder() + ")!>appender.Builder1() - & JavaWriterAppender.Builder2<*>..JavaWriterAppender.Builder1<*>? & JavaWriterAppender.Builder2<*>?")!>appender.intersectTwoSelfTypes() + appender.intersectTwoSelfTypes() } object WriterAppender { diff --git a/compiler/testData/diagnostics/tests/inline/returnedAnonymousObjects_2.fir.kt b/compiler/testData/diagnostics/tests/inline/returnedAnonymousObjects_2.fir.kt index b3a75c8701f..88f7b84c6f0 100644 --- a/compiler/testData/diagnostics/tests/inline/returnedAnonymousObjects_2.fir.kt +++ b/compiler/testData/diagnostics/tests/inline/returnedAnonymousObjects_2.fir.kt @@ -65,17 +65,17 @@ fun test10(b: Boolean) { } fun test11(b: Boolean) { - var x = foo11 { 1 }.value + var x = foo11 { 1 }.value if (b) { - x = foo11 { 2 }.value + x = foo11 { 2 }.value } x.bar() } fun test12(b: Boolean) { - var x = foo12 { 1 }.value.value + var x = foo12 { 1 }.value.value if (b) { - x = foo12 { 2 }.value.value + x = foo12 { 2 }.value.value } x.bar() } @@ -91,17 +91,17 @@ fun test20(b: Boolean) { } fun test21(b: Boolean) { - var x = foo21 { 1 }.value + var x = foo21 { 1 }.value if (b) { - x = foo21 { 2 }.value + x = foo21 { 2 }.value } x.bar() } fun test22(b: Boolean) { - var x = foo22 { 1 }.value.value + var x = foo22 { 1 }.value.value if (b) { - x = foo22 { 2 }.value.value + x = foo22 { 2 }.value.value } x.bar() } @@ -117,17 +117,17 @@ fun test30(b: Boolean) { } fun test31(b: Boolean) { - var x = foo31 { 1 }.value + var x = foo31 { 1 }.value if (b) { - x = foo31 { 2 }.value + x = foo31 { 2 }.value } x.bar() } fun test32(b: Boolean) { - var x = foo32 { 1 }.value.value + var x = foo32 { 1 }.value.value if (b) { - x = foo32 { 2 }.value.value + x = foo32 { 2 }.value.value } x.bar() } diff --git a/compiler/testData/diagnostics/tests/sealed/ExhaustiveOnCaptured.kt b/compiler/testData/diagnostics/tests/sealed/ExhaustiveOnCaptured.kt new file mode 100644 index 00000000000..318a55d60a5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/sealed/ExhaustiveOnCaptured.kt @@ -0,0 +1,18 @@ +// FIR_IDENTICAL + +abstract class FirBasedSymbol { + val fir: E get() = null!! +} +abstract class FirCallableSymbol : FirBasedSymbol() + +sealed class FirDeclaration +sealed class FirCallableDeclaration : FirDeclaration() + +class FirFunction : FirCallableDeclaration() +class FirVariable : FirCallableDeclaration() + +val FirCallableSymbol<*>.isExtension: Boolean + get() = when (fir) { + is FirFunction -> true + is FirVariable -> false + } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorCrazyProjections.fir.kt b/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorCrazyProjections.fir.kt index 1556957f654..da2ceb15576 100644 --- a/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorCrazyProjections.fir.kt +++ b/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorCrazyProjections.fir.kt @@ -10,6 +10,6 @@ fun listOf(): List = null!! // Unresolved reference is ok here: // we can't create a substituted signature for type alias constructor // since it has 'out' type projection in 'in' position. -val test1 = BOutIn(listOf(), null!!) +val test1 = BOutIn(listOf(), null!!) -val test2 = BInIn(listOf(), null!!) +val test2 = BInIn(listOf(), null!!) diff --git a/compiler/testData/ir/irText/expressions/sam/genericSamProjectedOut.fir.ir.txt b/compiler/testData/ir/irText/expressions/sam/genericSamProjectedOut.fir.ir.txt index 9e0e86afbca..5ecc2a5263d 100644 --- a/compiler/testData/ir/irText/expressions/sam/genericSamProjectedOut.fir.ir.txt +++ b/compiler/testData/ir/irText/expressions/sam/genericSamProjectedOut.fir.ir.txt @@ -7,7 +7,7 @@ FILE fqName: fileName:/genericSamProjectedOut.kt CALL 'public open fun someFunction (hello: @[FlexibleNullability] example.Hello<@[FlexibleNullability] A of example.SomeJavaClass?>?): kotlin.Unit declared in example.SomeJavaClass' type=kotlin.Unit origin=null $this: GET_VAR 'var a: example.SomeJavaClass declared in .test' type=example.SomeJavaClass origin=null hello: TYPE_OP type=example.Hello origin=SAM_CONVERSION typeOperand=example.Hello - FUN_EXPR type=kotlin.Function1<@[FlexibleNullability] kotlin.String?, kotlin.Unit> origin=LAMBDA + FUN_EXPR type=kotlin.Function1<@[FlexibleNullability] kotlin.Nothing?, kotlin.Unit> origin=LAMBDA FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> (it:@[FlexibleNullability] kotlin.String?) returnType:kotlin.Unit VALUE_PARAMETER name:it index:0 type:@[FlexibleNullability] kotlin.String? BLOCK_BODY @@ -17,7 +17,7 @@ FILE fqName: fileName:/genericSamProjectedOut.kt CALL 'public open fun plus (hello: @[FlexibleNullability] example.Hello<@[FlexibleNullability] A of example.SomeJavaClass?>?): @[FlexibleNullability] example.SomeJavaClass<@[FlexibleNullability] A of example.SomeJavaClass?>? declared in example.SomeJavaClass' type=@[FlexibleNullability] example.SomeJavaClass? origin=PLUS $this: GET_VAR 'var a: example.SomeJavaClass declared in .test' type=example.SomeJavaClass origin=null hello: TYPE_OP type=example.Hello origin=SAM_CONVERSION typeOperand=example.Hello - FUN_EXPR type=kotlin.Function1<@[FlexibleNullability] kotlin.String?, kotlin.Unit> origin=LAMBDA + FUN_EXPR type=kotlin.Function1<@[FlexibleNullability] kotlin.Nothing?, kotlin.Unit> origin=LAMBDA FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> (it:@[FlexibleNullability] kotlin.String?) returnType:kotlin.Unit VALUE_PARAMETER name:it index:0 type:@[FlexibleNullability] kotlin.String? BLOCK_BODY @@ -26,7 +26,7 @@ FILE fqName: fileName:/genericSamProjectedOut.kt CALL 'public open fun get (hello: @[FlexibleNullability] example.Hello<@[FlexibleNullability] A of example.SomeJavaClass?>?): kotlin.Unit declared in example.SomeJavaClass' type=kotlin.Unit origin=null $this: GET_VAR 'var a: example.SomeJavaClass declared in .test' type=example.SomeJavaClass origin=null hello: TYPE_OP type=example.Hello origin=SAM_CONVERSION typeOperand=example.Hello - FUN_EXPR type=kotlin.Function1<@[FlexibleNullability] kotlin.String?, kotlin.Unit> origin=LAMBDA + FUN_EXPR type=kotlin.Function1<@[FlexibleNullability] kotlin.Nothing?, kotlin.Unit> origin=LAMBDA FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> (it:@[FlexibleNullability] kotlin.String?) returnType:kotlin.Unit VALUE_PARAMETER name:it index:0 type:@[FlexibleNullability] kotlin.String? BLOCK_BODY @@ -36,17 +36,18 @@ FILE fqName: fileName:/genericSamProjectedOut.kt CALL 'public open fun plus (hello: @[FlexibleNullability] example.Hello<@[FlexibleNullability] A of example.SomeJavaClass?>?): @[FlexibleNullability] example.SomeJavaClass<@[FlexibleNullability] A of example.SomeJavaClass?>? declared in example.SomeJavaClass' type=@[FlexibleNullability] example.SomeJavaClass? origin=null $this: GET_VAR 'var a: example.SomeJavaClass declared in .test' type=example.SomeJavaClass origin=null hello: TYPE_OP type=example.Hello origin=SAM_CONVERSION typeOperand=example.Hello - FUN_EXPR type=kotlin.Function1<@[FlexibleNullability] kotlin.String?, kotlin.Unit> origin=LAMBDA + FUN_EXPR type=kotlin.Function1<@[FlexibleNullability] kotlin.Nothing?, kotlin.Unit> origin=LAMBDA FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> (it:@[FlexibleNullability] kotlin.String?) returnType:kotlin.Unit VALUE_PARAMETER name:it index:0 type:@[FlexibleNullability] kotlin.String? BLOCK_BODY RETURN type=kotlin.Nothing from='local final fun (it: @[FlexibleNullability] kotlin.String?): kotlin.Unit declared in .test' GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Unit modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.Unit CALL 'public open fun set (i: kotlin.Int, hello: @[FlexibleNullability] example.Hello<@[FlexibleNullability] A of example.SomeJavaClass?>?): kotlin.Unit declared in example.SomeJavaClass' type=kotlin.Unit origin=null - $this: GET_VAR 'var a: example.SomeJavaClass declared in .test' type=example.SomeJavaClass origin=null + $this: TYPE_OP type=example.SomeJavaClass origin=IMPLICIT_CAST typeOperand=example.SomeJavaClass + GET_VAR 'var a: example.SomeJavaClass declared in .test' type=example.SomeJavaClass origin=null i: CONST Int type=kotlin.Int value=0 hello: TYPE_OP type=example.Hello origin=SAM_CONVERSION typeOperand=example.Hello - FUN_EXPR type=kotlin.Function1<@[FlexibleNullability] kotlin.String?, kotlin.Unit> origin=LAMBDA + FUN_EXPR type=kotlin.Function1<@[FlexibleNullability] kotlin.Nothing?, kotlin.Unit> origin=LAMBDA FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> (it:@[FlexibleNullability] kotlin.String?) returnType:kotlin.Unit VALUE_PARAMETER name:it index:0 type:@[FlexibleNullability] kotlin.String? BLOCK_BODY diff --git a/compiler/testData/ir/irText/expressions/sam/genericSamProjectedOut.fir.kt.txt b/compiler/testData/ir/irText/expressions/sam/genericSamProjectedOut.fir.kt.txt index 0c5b8e9b4f9..7c2dda3d35c 100644 --- a/compiler/testData/ir/irText/expressions/sam/genericSamProjectedOut.fir.kt.txt +++ b/compiler/testData/ir/irText/expressions/sam/genericSamProjectedOut.fir.kt.txt @@ -16,7 +16,7 @@ fun test() { return Unit } /*-> Hello */) - a.set(i = 0, hello = local fun (it: @FlexibleNullability String?) { + a /*as SomeJavaClass */.set(i = 0, hello = local fun (it: @FlexibleNullability String?) { return Unit } /*-> Hello */) diff --git a/compiler/testData/ir/irText/types/genericFunWithStar.fir.ir.txt b/compiler/testData/ir/irText/types/genericFunWithStar.fir.ir.txt index ef5f0545c86..c8bec37521a 100644 --- a/compiler/testData/ir/irText/types/genericFunWithStar.fir.ir.txt +++ b/compiler/testData/ir/irText/types/genericFunWithStar.fir.ir.txt @@ -76,7 +76,7 @@ FILE fqName: fileName:/genericFunWithStar.kt VALUE_PARAMETER name:serializers index:0 type:kotlin.Array.I<*>> varargElementType:.I<*> [vararg] BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun bar (vararg serializers: .I<*>): .I<*> declared in .Box' - CALL 'public abstract fun foo (tSerializer: .I.Box.foo>): .I<.Box.Box.foo>> declared in .Box' type=.I.Box<*>> origin=null + CALL 'public abstract fun foo (tSerializer: .I.Box.foo>): .I<.Box.Box.foo>> declared in .Box' type=.I.Box.IBase>> origin=null : .IBase $this: GET_VAR ': .Box.Box> declared in .Box.bar' type=.Box.Box> origin=null tSerializer: CALL 'public final fun get (index: kotlin.Int): T of kotlin.Array declared in kotlin.Array' type=.I<*> origin=null 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 87c27ae3c05..405ebae99ac 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 @@ -17917,6 +17917,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/capturingFromArgumentOfFlexibleType.kt"); } + @Test + @TestMetadata("capturingOfDnn.kt") + public void testCapturingOfDnn() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/capturingOfDnn.kt"); + } + @Test @TestMetadata("differentCapturedTypes.kt") public void testDifferentCapturedTypes() throws Exception { @@ -33742,6 +33748,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/sealed/DoubleInner.kt"); } + @Test + @TestMetadata("ExhaustiveOnCaptured.kt") + public void testExhaustiveOnCaptured() throws Exception { + runTest("compiler/testData/diagnostics/tests/sealed/ExhaustiveOnCaptured.kt"); + } + @Test @TestMetadata("ExhaustiveOnRoot.kt") public void testExhaustiveOnRoot() throws Exception { diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/50.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/50.fir.kt index e4dd2ec20b8..37270eff4bc 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/50.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/50.fir.kt @@ -27,7 +27,7 @@ fun Any.case_2() { ")!>this.test() ")!>this.x ")!>this.y - x + x y } } @@ -49,7 +49,7 @@ fun T?.case_4() { & T?!!")!>this.test() & T?!!")!>this.x & T?!!")!>this.y - x + x y } } @@ -62,7 +62,7 @@ fun ClassWithSixTypeParameters.case_5() { & InterfaceWithFiveTypeParameters1<*, *, *, *, *> & ClassWithSixTypeParameters")!>this.test() & InterfaceWithFiveTypeParameters1<*, *, *, *, *> & ClassWithSixTypeParameters")!>this.x & InterfaceWithFiveTypeParameters1<*, *, *, *, *> & ClassWithSixTypeParameters")!>this.y - x + x y } } @@ -86,8 +86,8 @@ fun Inv.case_7() { if (this.prop_3 is MutableList<*>) { this.prop_3 this.prop_3[0] - & T!!")!>prop_3 - & T!!")!>prop_3[0] + & CapturedType(out T)!!")!>prop_3 + & CapturedType(out T)!!")!>prop_3[0] } } diff --git a/core/compiler.common/src/org/jetbrains/kotlin/types/model/TypeSystemContext.kt b/core/compiler.common/src/org/jetbrains/kotlin/types/model/TypeSystemContext.kt index b0a3d4a537d..1bc673a0459 100644 --- a/core/compiler.common/src/org/jetbrains/kotlin/types/model/TypeSystemContext.kt +++ b/core/compiler.common/src/org/jetbrains/kotlin/types/model/TypeSystemContext.kt @@ -229,6 +229,11 @@ interface TypeSystemInferenceExtensionContext : TypeSystemContext, TypeSystemBui fun CapturedTypeMarker.typeParameter(): TypeParameterMarker? fun CapturedTypeMarker.withNotNullProjection(): KotlinTypeMarker + /** + * Only for K2. + */ + fun CapturedTypeMarker.hasRawSuperType(): Boolean + fun TypeVariableMarker.defaultType(): SimpleTypeMarker fun createTypeWithAlternativeForIntersectionResult( diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/checker/ClassicTypeSystemContext.kt b/core/descriptors/src/org/jetbrains/kotlin/types/checker/ClassicTypeSystemContext.kt index e755500cbd7..f6ca687e934 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/checker/ClassicTypeSystemContext.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/checker/ClassicTypeSystemContext.kt @@ -533,6 +533,10 @@ interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext, TypeSy override fun CapturedTypeMarker.isOldCapturedType(): Boolean = this is CapturedType + override fun CapturedTypeMarker.hasRawSuperType(): Boolean { + error("Is not expected to be called in K1") + } + override fun KotlinTypeMarker.isNullableType(): Boolean { require(this is KotlinType, this::errorMessage) return TypeUtils.isNullableType(this)