diff --git a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java index e2694f20f07..d1f3e3f6c53 100644 --- a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java @@ -12234,6 +12234,11 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte runTest("compiler/testData/diagnostics/tests/inference/upperBounds/flexibilityInCommonSuperTypeCalculation.ni.kt"); } + @TestMetadata("inferringVariableByMaterializeAndUpperBound.kt") + public void testInferringVariableByMaterializeAndUpperBound() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/upperBounds/inferringVariableByMaterializeAndUpperBound.kt"); + } + @TestMetadata("intersectUpperBounds.kt") public void testIntersectUpperBounds() throws Exception { runTest("compiler/testData/diagnostics/tests/inference/upperBounds/intersectUpperBounds.kt"); diff --git a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestWithStdlibGenerated.java b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestWithStdlibGenerated.java index 4fa7f64cada..f9b31e8be6c 100644 --- a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestWithStdlibGenerated.java +++ b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestWithStdlibGenerated.java @@ -3038,29 +3038,6 @@ public class FirOldFrontendDiagnosticsTestWithStdlibGenerated extends AbstractFi runTest("compiler/testData/diagnostics/testsWithStdLib/inference/recursiveFlexibleAssertions.kt"); } - @TestMetadata("compiler/testData/diagnostics/testsWithStdLib/inference/addEqualityConstraintsWithoutSubtyping") - @TestDataPath("$PROJECT_ROOT") - @RunWith(JUnit3RunnerWithInners.class) - public static class AddEqualityConstraintsWithoutSubtyping extends AbstractFirOldFrontendDiagnosticsTestWithStdlib { - private void runTest(String testDataFilePath) throws Exception { - KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); - } - - public void testAllFilesPresentInAddEqualityConstraintsWithoutSubtyping() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/inference/addEqualityConstraintsWithoutSubtyping"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); - } - - @TestMetadata("kt41741.kt") - public void testKt41741() throws Exception { - runTest("compiler/testData/diagnostics/testsWithStdLib/inference/addEqualityConstraintsWithoutSubtyping/kt41741.kt"); - } - - @TestMetadata("kt42195.kt") - public void testKt42195() throws Exception { - runTest("compiler/testData/diagnostics/testsWithStdLib/inference/addEqualityConstraintsWithoutSubtyping/kt42195.kt"); - } - } - @TestMetadata("compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) @@ -3373,6 +3350,34 @@ public class FirOldFrontendDiagnosticsTestWithStdlibGenerated extends AbstractFi runTest("compiler/testData/diagnostics/testsWithStdLib/inference/nothingType/dontSpreadWarningToNotReturningNothingSubResolvedAtoms.kt"); } } + + @TestMetadata("compiler/testData/diagnostics/testsWithStdLib/inference/performance") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Performance extends AbstractFirOldFrontendDiagnosticsTestWithStdlib { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInPerformance() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/inference/performance"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @TestMetadata("kt41644.kt") + public void testKt41644() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/inference/performance/kt41644.kt"); + } + + @TestMetadata("kt41741.kt") + public void testKt41741() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/inference/performance/kt41741.kt"); + } + + @TestMetadata("kt42195.kt") + public void testKt42195() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/inference/performance/kt42195.kt"); + } + } } @TestMetadata("compiler/testData/diagnostics/testsWithStdLib/inline") diff --git a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintIncorporator.kt b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintIncorporator.kt index d326bc8e34c..06045c7b653 100644 --- a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintIncorporator.kt +++ b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintIncorporator.kt @@ -40,24 +40,12 @@ class ConstraintIncorporator( fun addNewIncorporatedConstraint(typeVariable: TypeVariableMarker, type: KotlinTypeMarker, constraintContext: ConstraintContext) } - fun incorporateEqualityConstraint(c: Context, typeVariable: TypeVariableMarker, constraint: Constraint) = with(c) { - // we shouldn't incorporate recursive constraint -- It is too dangerous - if (c.areThereRecursiveConstraints(typeVariable, constraint)) return - - c.directWithVariable(typeVariable, constraint) - if (constraint.type.contains { it is TypeVariableTypeConstructorMarker }) { - c.otherInsideMyConstraint(typeVariable, constraint) - } - c.insideOtherConstraint(typeVariable, constraint) - } - // \alpha is typeVariable, \beta -- other type variable registered in ConstraintStorage - fun incorporateSubtypeConstraint(c: Context, typeVariable: TypeVariableMarker, constraint: Constraint) { + fun incorporate(c: Context, typeVariable: TypeVariableMarker, constraint: Constraint) { // we shouldn't incorporate recursive constraint -- It is too dangerous if (c.areThereRecursiveConstraints(typeVariable, constraint)) return c.directWithVariable(typeVariable, constraint) - c.otherInsideMyConstraint(typeVariable, constraint) c.insideOtherConstraint(typeVariable, constraint) } @@ -98,26 +86,6 @@ class ConstraintIncorporator( } } - // \alpha <: Inv<\beta>, \beta <: Number => \alpha <: Inv - private fun Context.otherInsideMyConstraint( - typeVariable: TypeVariableMarker, - constraint: Constraint - ) { - val otherInMyConstraint = SmartSet.create() - constraint.type.contains { - otherInMyConstraint.addIfNotNull(this.getTypeVariable(it.typeConstructor())) - false - } - - for (otherTypeVariable in otherInMyConstraint) { - // to avoid ConcurrentModificationException - val otherConstraints = SmartList(this.getConstraintsForVariable(otherTypeVariable)) - for (otherConstraint in otherConstraints) { - generateNewConstraint(typeVariable, constraint, otherTypeVariable, otherConstraint) - } - } - } - // \alpha <: Number, \beta <: Inv<\alpha> => \beta <: Inv private fun Context.insideOtherConstraint( typeVariable: TypeVariableMarker, diff --git a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintInjector.kt b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintInjector.kt index 2ce05be83a5..3905e1461de 100644 --- a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintInjector.kt +++ b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintInjector.kt @@ -85,7 +85,7 @@ class ConstraintInjector( typeCheckerContext.setConstrainingTypesToPrintDebugInfo(lowerType, upperType) typeCheckerContext.runIsSubtypeOf(lowerType, upperType) - processConstraints(c, typeCheckerContext, constraintIncorporator::incorporateSubtypeConstraint) + processConstraints(c, typeCheckerContext) } private fun addEqualityConstraintAndIncorporateIt( @@ -97,14 +97,10 @@ class ConstraintInjector( typeCheckerContext.setConstrainingTypesToPrintDebugInfo(typeVariable, equalType) typeCheckerContext.addEqualityConstraint(typeVariable.typeConstructor(c), equalType) - processConstraints(c, typeCheckerContext, constraintIncorporator::incorporateEqualityConstraint) + processConstraints(c, typeCheckerContext) } - private fun processConstraints( - c: Context, - typeCheckerContext: TypeCheckerContext, - incorporate: (c: TypeCheckerContext, typeVariable: TypeVariableMarker, constraint: Constraint) -> Unit - ) { + private fun processConstraints(c: Context, typeCheckerContext: TypeCheckerContext) { while (typeCheckerContext.hasConstraintsToProcess()) { for ((typeVariable, constraint) in typeCheckerContext.extractAllConstraints()!!) { if (c.shouldWeSkipConstraint(typeVariable, constraint)) continue @@ -113,10 +109,17 @@ class ConstraintInjector( c.notFixedTypeVariables[typeVariable.freshTypeConstructor(c)] ?: typeCheckerContext.fixedTypeVariable(typeVariable) // it is important, that we add constraint here(not inside TypeCheckerContext), because inside incorporation we read constraints - constraints.addConstraint(constraint)?.let { - if (!constraint.isNullabilityConstraint) { - incorporate(typeCheckerContext, typeVariable, it) - } + val (addedOrNonRedundantExistedConstraint, wasAdded) = constraints.addConstraint(constraint) + val positionFrom = constraint.position.from + val constraintToIncorporate = when { + wasAdded && !constraint.isNullabilityConstraint -> addedOrNonRedundantExistedConstraint + positionFrom is FixVariableConstraintPosition<*> && positionFrom.variable == typeVariable && constraint.kind == EQUALITY -> + addedOrNonRedundantExistedConstraint + else -> null + } + + if (constraintToIncorporate != null) { + constraintIncorporator.incorporate(typeCheckerContext, typeVariable, constraintToIncorporate) } } @@ -255,9 +258,8 @@ class ConstraintInjector( isFromNullabilityConstraint: Boolean ) = addConstraint(typeVariable, subType, LOWER, isFromNullabilityConstraint) - override fun addEqualityConstraint(typeVariable: TypeConstructorMarker, type: KotlinTypeMarker) { + override fun addEqualityConstraint(typeVariable: TypeConstructorMarker, type: KotlinTypeMarker) = addConstraint(typeVariable, type, EQUALITY, false) - } private fun isCapturedTypeFromSubtyping(type: KotlinTypeMarker) = when ((type as? CapturedTypeMarker)?.captureStatus()) { diff --git a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/model/MutableConstraintStorage.kt b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/model/MutableConstraintStorage.kt index 8dd11dc1382..f235223fc93 100644 --- a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/model/MutableConstraintStorage.kt +++ b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/model/MutableConstraintStorage.kt @@ -47,8 +47,9 @@ class MutableVariableWithConstraints private constructor( private var simplifiedConstraints: SmartList? = mutableConstraints - // return new actual constraint, if this constraint is new - fun addConstraint(constraint: Constraint): Constraint? { + // return new actual constraint, if this constraint is new, otherwise return already existed not redundant constraint + // the second element of pair is a flag whether a constraint was added in fact + fun addConstraint(constraint: Constraint): Pair { val isLowerAndFlexibleTypeWithDefNotNullLowerBound = constraint.isLowerAndFlexibleTypeWithDefNotNullLowerBound() for (previousConstraint in constraints) { @@ -56,7 +57,10 @@ class MutableVariableWithConstraints private constructor( && previousConstraint.type == constraint.type && previousConstraint.isNullabilityConstraint == constraint.isNullabilityConstraint ) { - if (newConstraintIsUseless(previousConstraint, constraint)) return null + if (newConstraintIsUseless(previousConstraint, constraint)) { + return previousConstraint to false + } + val isMatchingForSimplification = when (previousConstraint.kind) { ConstraintKind.LOWER -> constraint.kind.isUpper() ConstraintKind.UPPER -> constraint.kind.isLower() @@ -75,14 +79,14 @@ class MutableVariableWithConstraints private constructor( } else constraint mutableConstraints.add(actualConstraint) simplifiedConstraints = null - return actualConstraint + return actualConstraint to true } } if (isLowerAndFlexibleTypeWithDefNotNullLowerBound && previousConstraint.isStrongerThanLowerAndFlexibleTypeWithDefNotNullLowerBound(constraint) ) { - return null + return previousConstraint to false } } @@ -95,7 +99,7 @@ class MutableVariableWithConstraints private constructor( simplifiedConstraints = null } - return constraint + return constraint to true } // This method should be used only for transaction in constraint system diff --git a/compiler/testData/diagnostics/tests/inference/commonSystem/cstWithTypeContainingNonFixedVariable.kt b/compiler/testData/diagnostics/tests/inference/commonSystem/cstWithTypeContainingNonFixedVariable.kt index ece139a8b99..41441411794 100644 --- a/compiler/testData/diagnostics/tests/inference/commonSystem/cstWithTypeContainingNonFixedVariable.kt +++ b/compiler/testData/diagnostics/tests/inference/commonSystem/cstWithTypeContainingNonFixedVariable.kt @@ -59,11 +59,11 @@ fun testVariableWithBound() { ")!>c1 - val c2 = select(SubInv(), createWithNumberBound()) + val c2 = select(SubInv(), createWithNumberBound()) ")!>c2 - val c3 = select(SubInv(), createWithIntBound()) + val c3 = select(SubInv(), createWithIntBound()) ")!>c3 } diff --git a/compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/basic.kt b/compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/basic.kt index 07c7cc5a200..2c102c68e2f 100644 --- a/compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/basic.kt +++ b/compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/basic.kt @@ -119,8 +119,8 @@ fun main() { * K <: (A) -> Unit -> TypeVariable(_RP1) >: A * K >: (C) -> TypeVariable(_R) -> TypeVariable(_RP1) <: C */ - val x12 = selectC(id { it }, id { x: B -> }) - val x13 = selectA(id { it }, id { x: C -> }) + val x12 = selectC(id { it }, id { x: B -> }) + val x13 = selectA(id { it }, id { x: C -> }) val x14 = selectC(id { it }, id { x: A -> }, { x -> x }) val x15 = selectC(id { it }, { x: A -> }, id { x -> x }) /* @@ -138,8 +138,8 @@ fun main() { * K <: (C) -> Unit -> TypeVariable(_RP1) >: C * K == (B) -> Unit -> TypeVariable(_RP1) == B */ - val x17: (C) -> Unit = selectB(id { it }, id { it }, id<(B) -> Unit> { x -> x }) - val x18: (C) -> Unit = select(id { it }, { it }, id<(B) -> Unit> { x -> x }) + val x17: (C) -> Unit = selectB(id { it }, id { it }, id<(B) -> Unit> { x -> x }) + val x18: (C) -> Unit = select(id { it }, { it }, id<(B) -> Unit> { x -> x }) // Resolution of extension/non-extension functions combination val x19: String.() -> Unit = select( kotlin.Unit")!>id { this }, kotlin.Unit")!>id(fun(x: String) {})) diff --git a/compiler/testData/diagnostics/tests/inference/upperBounds/flexibilityInCommonSuperTypeCalculation.ni.kt b/compiler/testData/diagnostics/tests/inference/upperBounds/flexibilityInCommonSuperTypeCalculation.ni.kt index f1978bf64d9..21aa9aeabef 100644 --- a/compiler/testData/diagnostics/tests/inference/upperBounds/flexibilityInCommonSuperTypeCalculation.ni.kt +++ b/compiler/testData/diagnostics/tests/inference/upperBounds/flexibilityInCommonSuperTypeCalculation.ni.kt @@ -240,11 +240,11 @@ fun case_13() { result_4 result_5 result_6 - ")!>result_7 - ")!>result_8 - ")!>result_9 - ")!>result_10 - ")!>result_11 + ..kotlin.collections.List<(kotlin.Int..kotlin.Int?)>?)>")!>result_7 + ..kotlin.collections.List<(kotlin.Int..kotlin.Int?)>?)>")!>result_8 + ..kotlin.collections.List<(kotlin.Int..kotlin.Int?)>?)>")!>result_9 + >")!>result_10 + ?>")!>result_11 ")!>result_12 } diff --git a/compiler/testData/diagnostics/tests/inference/upperBounds/inferringVariableByMaterializeAndUpperBound.fir.kt b/compiler/testData/diagnostics/tests/inference/upperBounds/inferringVariableByMaterializeAndUpperBound.fir.kt new file mode 100644 index 00000000000..252b7fedfcb --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/upperBounds/inferringVariableByMaterializeAndUpperBound.fir.kt @@ -0,0 +1,14 @@ +// !DIAGNOSTICS: -CAST_NEVER_SUCCEEDS + +interface I + +interface Inv

+interface Out + +class Bar(val x: Inv>) + +fun materializeFoo(): Inv = null as Inv + +fun main() { + Bar(materializeFoo()) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/upperBounds/inferringVariableByMaterializeAndUpperBound.kt b/compiler/testData/diagnostics/tests/inference/upperBounds/inferringVariableByMaterializeAndUpperBound.kt new file mode 100644 index 00000000000..7bbe9a58142 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/upperBounds/inferringVariableByMaterializeAndUpperBound.kt @@ -0,0 +1,14 @@ +// !DIAGNOSTICS: -CAST_NEVER_SUCCEEDS + +interface I + +interface Inv

+interface Out + +class Bar(val x: Inv>) + +fun materializeFoo(): Inv = null as Inv + +fun main() { + Bar(materializeFoo()) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/upperBounds/inferringVariableByMaterializeAndUpperBound.txt b/compiler/testData/diagnostics/tests/inference/upperBounds/inferringVariableByMaterializeAndUpperBound.txt new file mode 100644 index 00000000000..27fac7e5e53 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/upperBounds/inferringVariableByMaterializeAndUpperBound.txt @@ -0,0 +1,30 @@ +package + +public fun main(): kotlin.Unit +public fun materializeFoo(): Inv + +public final class Bar { + public constructor Bar(/*0*/ x: Inv>) + public final val x: Inv> + 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 I { + 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 Inv { + 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 Out { + 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 +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/completion/postponedArgumentsAnalysis/suspendFunctions.kt b/compiler/testData/diagnostics/testsWithStdLib/inference/completion/postponedArgumentsAnalysis/suspendFunctions.kt index 770c150974a..be8a30e59c5 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/inference/completion/postponedArgumentsAnalysis/suspendFunctions.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/completion/postponedArgumentsAnalysis/suspendFunctions.kt @@ -19,7 +19,7 @@ fun main() { val x1: suspend (Int) -> Unit = takeSuspend( kotlin.Unit")!>id { it }, kotlin.Unit")!>{ x -> x }) // Here, the error should be - val x2: (Int) -> Unit = takeSuspend( kotlin.Unit")!>id { it }, kotlin.Unit"), TYPE_MISMATCH, TYPE_MISMATCH, TYPE_MISMATCH, TYPE_MISMATCH, TYPE_MISMATCH!>{ x -> x }) - val x3: suspend (Int) -> Unit = takeSimpleFunction( kotlin.Unit")!>id { it }, kotlin.Unit"), TYPE_MISMATCH, TYPE_MISMATCH, TYPE_MISMATCH, TYPE_MISMATCH, TYPE_MISMATCH!>{ x -> x }) - val x4: (Int) -> Unit = takeSimpleFunction(id Unit> {}, kotlin.Unit"), TYPE_MISMATCH, TYPE_MISMATCH, TYPE_MISMATCH, TYPE_MISMATCH, TYPE_MISMATCH, TYPE_MISMATCH, TYPE_MISMATCH, TYPE_MISMATCH, TYPE_MISMATCH, TYPE_MISMATCH!>{}) + val x2: (Int) -> Unit = takeSuspend( kotlin.Unit")!>id { it }, kotlin.Unit"), TYPE_MISMATCH, TYPE_MISMATCH, TYPE_MISMATCH!>{ x -> x }) + val x3: suspend (Int) -> Unit = takeSimpleFunction( kotlin.Unit")!>id { it }, kotlin.Unit"), TYPE_MISMATCH, TYPE_MISMATCH, TYPE_MISMATCH!>{ x -> x }) + val x4: (Int) -> Unit = takeSimpleFunction(id Unit> {}, kotlin.Unit"), TYPE_MISMATCH, TYPE_MISMATCH, TYPE_MISMATCH, TYPE_MISMATCH, TYPE_MISMATCH, TYPE_MISMATCH!>{}) } diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/performance/kt41644.kt b/compiler/testData/diagnostics/testsWithStdLib/inference/performance/kt41644.kt new file mode 100644 index 00000000000..bf660e84702 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/performance/kt41644.kt @@ -0,0 +1,44 @@ +// FIR_IDENTICAL +//!DIAGNOSTICS: -UNUSED_PARAMETER -CAST_NEVER_SUCCEEDS + +sealed class DataType { + sealed class NotNull : DataType() { + abstract class Partial : NotNull() + } +} + +class Tuple8, B, DB : DataType, C, DC : DataType, D, DD : DataType, E, DE : DataType, F, DF : DataType, G, DG : DataType, H, DH : DataType>( + firstName: String, firstType: DA, + secondName: String, secondType: DB, + thirdName: String, thirdType: DC, + fourthName: String, fourthType: DD, + fifthName: String, fifthType: DE, + sixthName: String, sixthType: DF, + seventhName: String, seventhType: DG, + eighthName: String, eighthType: DH +) : Schema>() + +class EitherType>( + schema: SCH +) + +open class Schema + +fun , B, DB : DataType, C, DC : DataType, D, DD : DataType, E, DE : DataType, F, DF : DataType, G, DG : DataType, H, DH : DataType> either8( + firstName: String, firstType: DA, + secondName: String, secondType: DB, + thirdName: String, thirdType: DC, + fourthName: String, fourthType: DD, + fifthName: String, fifthType: DE, + sixthName: String, sixthType: DF, + seventhName: String, seventhType: DG, + eighthName: String, eighthType: DH +): DataType.NotNull.Partial> = + EitherType( + Tuple8( + firstName, firstType, secondName, secondType, thirdName, thirdType, fourthName, fourthType, + fifthName, fifthType, sixthName, sixthType, seventhName, seventhType, eighthName, eighthType + ) + ) as DataType.NotNull.Partial> + +class Either8 diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/performance/kt41644.txt b/compiler/testData/diagnostics/testsWithStdLib/inference/performance/kt41644.txt new file mode 100644 index 00000000000..8fc7f0bc599 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/performance/kt41644.txt @@ -0,0 +1,52 @@ +package + +public fun , /*2*/ B, /*3*/ DB : DataType, /*4*/ C, /*5*/ DC : DataType, /*6*/ D, /*7*/ DD : DataType, /*8*/ E, /*9*/ DE : DataType, /*10*/ F, /*11*/ DF : DataType, /*12*/ G, /*13*/ DG : DataType, /*14*/ H, /*15*/ DH : DataType> either8(/*0*/ firstName: kotlin.String, /*1*/ firstType: DA, /*2*/ secondName: kotlin.String, /*3*/ secondType: DB, /*4*/ thirdName: kotlin.String, /*5*/ thirdType: DC, /*6*/ fourthName: kotlin.String, /*7*/ fourthType: DD, /*8*/ fifthName: kotlin.String, /*9*/ fifthType: DE, /*10*/ sixthName: kotlin.String, /*11*/ sixthType: DF, /*12*/ seventhName: kotlin.String, /*13*/ seventhType: DG, /*14*/ eighthName: kotlin.String, /*15*/ eighthType: DH): DataType.NotNull.Partial> + +public sealed class DataType { + private constructor DataType() + 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 sealed class NotNull : DataType { + private constructor NotNull() + 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 abstract class Partial : DataType.NotNull { + public constructor Partial() + 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 final class Either8 { + public constructor Either8() + 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 final class EitherType> { + public constructor EitherType>(/*0*/ schema: SCH) + 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 Schema { + public constructor Schema() + 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 final class Tuple8, /*2*/ B, /*3*/ DB : DataType, /*4*/ C, /*5*/ DC : DataType, /*6*/ D, /*7*/ DD : DataType, /*8*/ E, /*9*/ DE : DataType, /*10*/ F, /*11*/ DF : DataType, /*12*/ G, /*13*/ DG : DataType, /*14*/ H, /*15*/ DH : DataType> : Schema> { + public constructor Tuple8, /*2*/ B, /*3*/ DB : DataType, /*4*/ C, /*5*/ DC : DataType, /*6*/ D, /*7*/ DD : DataType, /*8*/ E, /*9*/ DE : DataType, /*10*/ F, /*11*/ DF : DataType, /*12*/ G, /*13*/ DG : DataType, /*14*/ H, /*15*/ DH : DataType>(/*0*/ firstName: kotlin.String, /*1*/ firstType: DA, /*2*/ secondName: kotlin.String, /*3*/ secondType: DB, /*4*/ thirdName: kotlin.String, /*5*/ thirdType: DC, /*6*/ fourthName: kotlin.String, /*7*/ fourthType: DD, /*8*/ fifthName: kotlin.String, /*9*/ fifthType: DE, /*10*/ sixthName: kotlin.String, /*11*/ sixthType: DF, /*12*/ seventhName: kotlin.String, /*13*/ seventhType: DG, /*14*/ eighthName: kotlin.String, /*15*/ eighthType: DH) + 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 +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/addEqualityConstraintsWithoutSubtyping/kt41741.kt b/compiler/testData/diagnostics/testsWithStdLib/inference/performance/kt41741.kt similarity index 100% rename from compiler/testData/diagnostics/testsWithStdLib/inference/addEqualityConstraintsWithoutSubtyping/kt41741.kt rename to compiler/testData/diagnostics/testsWithStdLib/inference/performance/kt41741.kt diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/addEqualityConstraintsWithoutSubtyping/kt41741.txt b/compiler/testData/diagnostics/testsWithStdLib/inference/performance/kt41741.txt similarity index 100% rename from compiler/testData/diagnostics/testsWithStdLib/inference/addEqualityConstraintsWithoutSubtyping/kt41741.txt rename to compiler/testData/diagnostics/testsWithStdLib/inference/performance/kt41741.txt diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/addEqualityConstraintsWithoutSubtyping/kt42195.kt b/compiler/testData/diagnostics/testsWithStdLib/inference/performance/kt42195.kt similarity index 100% rename from compiler/testData/diagnostics/testsWithStdLib/inference/addEqualityConstraintsWithoutSubtyping/kt42195.kt rename to compiler/testData/diagnostics/testsWithStdLib/inference/performance/kt42195.kt diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/addEqualityConstraintsWithoutSubtyping/kt42195.txt b/compiler/testData/diagnostics/testsWithStdLib/inference/performance/kt42195.txt similarity index 100% rename from compiler/testData/diagnostics/testsWithStdLib/inference/addEqualityConstraintsWithoutSubtyping/kt42195.txt rename to compiler/testData/diagnostics/testsWithStdLib/inference/performance/kt42195.txt diff --git a/compiler/testData/diagnostics/testsWithStdLib/tryCatch/tryExpression.kt b/compiler/testData/diagnostics/testsWithStdLib/tryCatch/tryExpression.kt index 7bca0381a93..a1202adfcb2 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/tryCatch/tryExpression.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/tryCatch/tryExpression.kt @@ -27,7 +27,7 @@ fun test1(): Map = run { } fun test2(): Map = run { - try { + try { emptyMap() } catch (e: ExcA) { mapOf("" to "") diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index bf42951674e..1da5d58a8a7 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -12241,6 +12241,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTestWithFirVali runTest("compiler/testData/diagnostics/tests/inference/upperBounds/flexibilityInCommonSuperTypeCalculation.ni.kt"); } + @TestMetadata("inferringVariableByMaterializeAndUpperBound.kt") + public void testInferringVariableByMaterializeAndUpperBound() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/upperBounds/inferringVariableByMaterializeAndUpperBound.kt"); + } + @TestMetadata("intersectUpperBounds.kt") public void testIntersectUpperBounds() throws Exception { runTest("compiler/testData/diagnostics/tests/inference/upperBounds/intersectUpperBounds.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java index 3a3b01d4bd6..102b487a90c 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java @@ -3188,29 +3188,6 @@ public class DiagnosticsTestWithStdLibGenerated extends AbstractDiagnosticsTestW runTest("compiler/testData/diagnostics/testsWithStdLib/inference/recursiveFlexibleAssertions.kt"); } - @TestMetadata("compiler/testData/diagnostics/testsWithStdLib/inference/addEqualityConstraintsWithoutSubtyping") - @TestDataPath("$PROJECT_ROOT") - @RunWith(JUnit3RunnerWithInners.class) - public static class AddEqualityConstraintsWithoutSubtyping extends AbstractDiagnosticsTestWithStdLib { - private void runTest(String testDataFilePath) throws Exception { - KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); - } - - public void testAllFilesPresentInAddEqualityConstraintsWithoutSubtyping() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/inference/addEqualityConstraintsWithoutSubtyping"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); - } - - @TestMetadata("kt41741.kt") - public void testKt41741() throws Exception { - runTest("compiler/testData/diagnostics/testsWithStdLib/inference/addEqualityConstraintsWithoutSubtyping/kt41741.kt"); - } - - @TestMetadata("kt42195.kt") - public void testKt42195() throws Exception { - runTest("compiler/testData/diagnostics/testsWithStdLib/inference/addEqualityConstraintsWithoutSubtyping/kt42195.kt"); - } - } - @TestMetadata("compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) @@ -3523,6 +3500,34 @@ public class DiagnosticsTestWithStdLibGenerated extends AbstractDiagnosticsTestW runTest("compiler/testData/diagnostics/testsWithStdLib/inference/nothingType/dontSpreadWarningToNotReturningNothingSubResolvedAtoms.kt"); } } + + @TestMetadata("compiler/testData/diagnostics/testsWithStdLib/inference/performance") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Performance extends AbstractDiagnosticsTestWithStdLib { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInPerformance() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/inference/performance"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @TestMetadata("kt41644.kt") + public void testKt41644() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/inference/performance/kt41644.kt"); + } + + @TestMetadata("kt41741.kt") + public void testKt41741() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/inference/performance/kt41741.kt"); + } + + @TestMetadata("kt42195.kt") + public void testKt42195() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/inference/performance/kt42195.kt"); + } + } } @TestMetadata("compiler/testData/diagnostics/testsWithStdLib/inline") diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java index da03bc7b198..25a24d11639 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java @@ -3188,29 +3188,6 @@ public class DiagnosticsTestWithStdLibUsingJavacGenerated extends AbstractDiagno runTest("compiler/testData/diagnostics/testsWithStdLib/inference/recursiveFlexibleAssertions.kt"); } - @TestMetadata("compiler/testData/diagnostics/testsWithStdLib/inference/addEqualityConstraintsWithoutSubtyping") - @TestDataPath("$PROJECT_ROOT") - @RunWith(JUnit3RunnerWithInners.class) - public static class AddEqualityConstraintsWithoutSubtyping extends AbstractDiagnosticsTestWithStdLibUsingJavac { - private void runTest(String testDataFilePath) throws Exception { - KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); - } - - public void testAllFilesPresentInAddEqualityConstraintsWithoutSubtyping() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/inference/addEqualityConstraintsWithoutSubtyping"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); - } - - @TestMetadata("kt41741.kt") - public void testKt41741() throws Exception { - runTest("compiler/testData/diagnostics/testsWithStdLib/inference/addEqualityConstraintsWithoutSubtyping/kt41741.kt"); - } - - @TestMetadata("kt42195.kt") - public void testKt42195() throws Exception { - runTest("compiler/testData/diagnostics/testsWithStdLib/inference/addEqualityConstraintsWithoutSubtyping/kt42195.kt"); - } - } - @TestMetadata("compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) @@ -3523,6 +3500,34 @@ public class DiagnosticsTestWithStdLibUsingJavacGenerated extends AbstractDiagno runTest("compiler/testData/diagnostics/testsWithStdLib/inference/nothingType/dontSpreadWarningToNotReturningNothingSubResolvedAtoms.kt"); } } + + @TestMetadata("compiler/testData/diagnostics/testsWithStdLib/inference/performance") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Performance extends AbstractDiagnosticsTestWithStdLibUsingJavac { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInPerformance() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/inference/performance"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @TestMetadata("kt41644.kt") + public void testKt41644() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/inference/performance/kt41644.kt"); + } + + @TestMetadata("kt41741.kt") + public void testKt41741() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/inference/performance/kt41741.kt"); + } + + @TestMetadata("kt42195.kt") + public void testKt42195() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/inference/performance/kt42195.kt"); + } + } } @TestMetadata("compiler/testData/diagnostics/testsWithStdLib/inline") diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java index 2c8875e5bf0..2268109725c 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java @@ -12236,6 +12236,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing runTest("compiler/testData/diagnostics/tests/inference/upperBounds/flexibilityInCommonSuperTypeCalculation.ni.kt"); } + @TestMetadata("inferringVariableByMaterializeAndUpperBound.kt") + public void testInferringVariableByMaterializeAndUpperBound() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/upperBounds/inferringVariableByMaterializeAndUpperBound.kt"); + } + @TestMetadata("intersectUpperBounds.kt") public void testIntersectUpperBounds() throws Exception { runTest("compiler/testData/diagnostics/tests/inference/upperBounds/intersectUpperBounds.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 1b2791231c1..430a827ede8 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -271,6 +271,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/annotations/typeAnnotations"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true); } + @TestMetadata("checkingNotincorporatedInputTypes.kt") + public void testCheckingNotincorporatedInputTypes() throws Exception { + runTest("compiler/testData/codegen/box/annotations/typeAnnotations/checkingNotincorporatedInputTypes.kt"); + } + @TestMetadata("implicitReturn.kt") public void testImplicitReturn() throws Exception { runTest("compiler/testData/codegen/box/annotations/typeAnnotations/implicitReturn.kt");