From 70c89a28e1ab21ad1f0d3f5370c80a5f4eed1a0e Mon Sep 17 00:00:00 2001 From: Ilya Chernikov Date: Fri, 21 Feb 2020 16:39:52 +0100 Subject: [PATCH] Stop subtyping constraint search if equality constraints for... all not fixed type vars are found #KT-35626 fixed --- ...irOldFrontendDiagnosticsTestGenerated.java | 10 +++++ .../components/ConstraintInjector.kt | 37 ++++++++++++++----- compiler/testData/diagnostics/tests/Bounds.kt | 4 +- .../annotations/annotationRenderingInTypes.kt | 2 +- .../genericFunctionsWithNullableTypes.kt | 2 +- .../argumentsOfAnnotation.kt | 2 +- .../argumentsOfAnnotationWithKClass.kt | 4 +- .../basicCollectionLiterals.kt | 2 +- .../defaultValuesInAnnotation.kt | 6 +-- .../delegation/DelegationExpectedType.kt | 2 +- .../tests/generics/innerClasses/innerTP.kt | 2 +- .../cannotCaptureInProjection.kt | 8 ++-- .../captureTypeOnlyOnTopLevel.kt | 4 +- .../tests/inference/completion/kt33166.kt | 2 +- .../tests/inference/constraints/kt6320.kt | 2 +- .../tests/inference/dependantOnVariance.kt | 2 +- .../typeInferenceExpectedTypeMismatch.kt | 4 +- .../useBoundsToInferTypeParamsSimple.kt | 2 +- .../classTypeParameterInferredFromArgument.kt | 2 +- .../j+k/genericConstructor/innerClass.kt | 2 +- .../noClassTypeParametersInvParameter.kt | 4 +- .../numbers/numbersInSimpleConstraints.kt | 2 +- .../diagnostics/tests/regressions/kt35626.kt | 24 ++++++++++++ .../diagnostics/tests/regressions/kt35626.txt | 31 ++++++++++++++++ .../tests/regressions/kt35626small.kt | 22 +++++++++++ .../tests/regressions/kt35626small.txt | 22 +++++++++++ .../errors/typeInferenceErrorForInvoke.kt | 4 +- .../specialConstructions/constantsInIf.kt | 2 +- .../constructorCallType.kt | 2 +- .../smartCasts/inference/intersectionTypes.kt | 4 +- .../implicitNothingInReturnPosition.kt | 2 +- ...boundsViolationInDeepTypeAliasExpansion.kt | 2 +- .../boundsViolationInTypeAliasExpansion.kt | 2 +- ...ximationInTypeAliasArgumentSubstitution.kt | 2 +- ...asConstructorTypeArgumentsInference.ni.txt | 6 +-- ...orTypeArgumentsInferenceWithNestedCalls.kt | 2 +- .../testData/diagnostics/tests/when/kt9972.kt | 2 +- .../kClassArrayInAnnotationsInVariance.kt | 4 +- .../kClassArrayInAnnotationsOutVariance.kt | 6 +-- .../testsWithStdLib/elvisOnJavaList.kt | 2 +- .../testsWithStdLib/tryCatch/tryExpression.kt | 2 +- .../checkers/DiagnosticsTestGenerated.java | 10 +++++ .../DiagnosticsUsingJavacTestGenerated.java | 10 +++++ .../typeParameters/rawTypeCast.kt | 1 + nj2k/testData/newJ2k/toArray/toArray.kt | 1 - .../newJ2k/typeParameters/rawTypeCast.kt | 2 + 46 files changed, 211 insertions(+), 63 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/regressions/kt35626.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt35626.txt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt35626small.kt create mode 100644 compiler/testData/diagnostics/tests/regressions/kt35626small.txt diff --git a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java index 9ac22d573d1..42b324e8bf8 100644 --- a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java @@ -18074,6 +18074,16 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte runTest("compiler/testData/diagnostics/tests/regressions/kt3535.kt"); } + @TestMetadata("kt35626.kt") + public void testKt35626() throws Exception { + runTest("compiler/testData/diagnostics/tests/regressions/kt35626.kt"); + } + + @TestMetadata("kt35626small.kt") + public void testKt35626small() throws Exception { + runTest("compiler/testData/diagnostics/tests/regressions/kt35626small.kt"); + } + @TestMetadata("kt35668.kt") public void testKt35668() throws Exception { runTest("compiler/testData/diagnostics/tests/regressions/kt35668.kt"); diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintInjector.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintInjector.kt index 4c151839570..bd73c401b6a 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintInjector.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintInjector.kt @@ -17,6 +17,7 @@ package org.jetbrains.kotlin.resolve.calls.inference.components +import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemOperation import org.jetbrains.kotlin.resolve.calls.inference.model.* import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintKind.LOWER import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintKind.UPPER @@ -26,6 +27,7 @@ import org.jetbrains.kotlin.types.checker.KotlinTypeRefiner import org.jetbrains.kotlin.types.model.* import org.jetbrains.kotlin.types.refinement.TypeRefinement import java.util.* +import kotlin.collections.ArrayList import kotlin.math.max class ConstraintInjector( @@ -69,23 +71,38 @@ class ConstraintInjector( upperType: KotlinTypeMarker, incorporatePosition: IncorporationConstraintPosition ) { - val possibleNewConstraints = Stack>() + val possibleNewConstraints = ArrayList>() val typeCheckerContext = TypeCheckerContext(c, incorporatePosition, lowerType, upperType, possibleNewConstraints) typeCheckerContext.runIsSubtypeOf(lowerType, upperType) while (possibleNewConstraints.isNotEmpty()) { - val (typeVariable, constraint) = possibleNewConstraints.pop() - if (c.shouldWeSkipConstraint(typeVariable, constraint)) continue - val constraints = - c.notFixedTypeVariables[typeVariable.freshTypeConstructor(c)] ?: typeCheckerContext.fixedTypeVariable(typeVariable) + val constraintsToProcess = possibleNewConstraints.toTypedArray() + possibleNewConstraints.clear() + for ((typeVariable, constraint) in constraintsToProcess) { + if (c.shouldWeSkipConstraint(typeVariable, constraint)) continue - // it is important, that we add constraint here(not inside TypeCheckerContext), because inside incorporation we read constraints - constraints.addConstraint(constraint)?.let { - if (!constraint.isNullabilityConstraint) { - constraintIncorporator.incorporate(typeCheckerContext, typeVariable, it) + val constraints = + 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) { + constraintIncorporator.incorporate(typeCheckerContext, typeVariable, it) + } } } + + val contextOps = c as? ConstraintSystemOperation + if (possibleNewConstraints == null || + (contextOps != null && c.notFixedTypeVariables.all { typeVariable -> + typeVariable.value.constraints.any { constraint -> + constraint.kind == ConstraintKind.EQUALITY && contextOps.isProperType(constraint.type) + } + }) + ) { + break + } } } @@ -122,7 +139,7 @@ class ConstraintInjector( val position: IncorporationConstraintPosition, val baseLowerType: KotlinTypeMarker, val baseUpperType: KotlinTypeMarker, - val possibleNewConstraints: MutableList> + val possibleNewConstraints: MutableCollection> ) : AbstractTypeCheckerContextForConstraintSystem(), ConstraintIncorporator.Context, TypeSystemInferenceExtensionContext by c { val baseContext: AbstractTypeCheckerContext = newBaseTypeCheckerContext(isErrorTypeEqualsToAnything, isStubTypeEqualsToAnything) diff --git a/compiler/testData/diagnostics/tests/Bounds.kt b/compiler/testData/diagnostics/tests/Bounds.kt index 657750b52dd..d91a22dc5c3 100644 --- a/compiler/testData/diagnostics/tests/Bounds.kt +++ b/compiler/testData/diagnostics/tests/Bounds.kt @@ -7,12 +7,12 @@ package boundsWithSubstitutors class C : A() val a = B() - val a1 = B<Int>() + val a1 = B<Int>() class X() val b = X, C>>() - val b0 = XAny?>() + val b0 = XAny?>() val b1 = X, String>>() // FILE: b.kt diff --git a/compiler/testData/diagnostics/tests/annotations/annotationRenderingInTypes.kt b/compiler/testData/diagnostics/tests/annotations/annotationRenderingInTypes.kt index 12accf90560..bc162fd28f7 100644 --- a/compiler/testData/diagnostics/tests/annotations/annotationRenderingInTypes.kt +++ b/compiler/testData/diagnostics/tests/annotations/annotationRenderingInTypes.kt @@ -13,7 +13,7 @@ annotation class Ann fun <@Ann R : @Ann Any> f3(a: Array<@Ann R>): Array<@Ann R?> = null!! fun test2(a: @Ann Array) { - val r: Array = f3(a) + val r: Array = f3(a) } diff --git a/compiler/testData/diagnostics/tests/callableReference/generic/genericFunctionsWithNullableTypes.kt b/compiler/testData/diagnostics/tests/callableReference/generic/genericFunctionsWithNullableTypes.kt index 5519d74be29..79377bf1e1f 100644 --- a/compiler/testData/diagnostics/tests/callableReference/generic/genericFunctionsWithNullableTypes.kt +++ b/compiler/testData/diagnostics/tests/callableReference/generic/genericFunctionsWithNullableTypes.kt @@ -29,7 +29,7 @@ fun test(x: T) { baz(1, null, ::foo) baz(null, null, ::foo) - val s3: Pair = bar(null, null, ::foo) + val s3: Pair = bar(null, null, ::foo) val s4: Pair = bar(null, null, ::foo) val s5: Pair = bar(1, "", ::foo) diff --git a/compiler/testData/diagnostics/tests/collectionLiterals/argumentsOfAnnotation.kt b/compiler/testData/diagnostics/tests/collectionLiterals/argumentsOfAnnotation.kt index c6f263b033b..6edf95ba193 100644 --- a/compiler/testData/diagnostics/tests/collectionLiterals/argumentsOfAnnotation.kt +++ b/compiler/testData/diagnostics/tests/collectionLiterals/argumentsOfAnnotation.kt @@ -9,7 +9,7 @@ fun test1() {} @Foo([], [], []) fun test2() {} -@Foo([1f], [' '], [1]) +@Foo([1f], [' '], [1]) fun test3() {} @Foo(c = [1f], b = [""], a = [1]) diff --git a/compiler/testData/diagnostics/tests/collectionLiterals/argumentsOfAnnotationWithKClass.kt b/compiler/testData/diagnostics/tests/collectionLiterals/argumentsOfAnnotationWithKClass.kt index ff88bc0a4ab..d6b580b90c3 100644 --- a/compiler/testData/diagnostics/tests/collectionLiterals/argumentsOfAnnotationWithKClass.kt +++ b/compiler/testData/diagnostics/tests/collectionLiterals/argumentsOfAnnotationWithKClass.kt @@ -21,10 +21,10 @@ fun test3() {} @Foo([Gen::class]) fun test4() {} -@Foo([""]) +@Foo([""]) fun test5() {} -@Foo([Int::class, 1]) +@Foo([Int::class, 1]) fun test6() {} @Bar diff --git a/compiler/testData/diagnostics/tests/collectionLiterals/basicCollectionLiterals.kt b/compiler/testData/diagnostics/tests/collectionLiterals/basicCollectionLiterals.kt index 4bb7359054c..3a7a4ec7c5e 100644 --- a/compiler/testData/diagnostics/tests/collectionLiterals/basicCollectionLiterals.kt +++ b/compiler/testData/diagnostics/tests/collectionLiterals/basicCollectionLiterals.kt @@ -7,7 +7,7 @@ fun test() { val b: Array = [] val c = [1, 2] val d: Array = [1, 2] - val e: Array = [1] + val e: Array = [1] val f: IntArray = [1, 2] val g = [f] diff --git a/compiler/testData/diagnostics/tests/collectionLiterals/defaultValuesInAnnotation.kt b/compiler/testData/diagnostics/tests/collectionLiterals/defaultValuesInAnnotation.kt index cb9ce738e78..7cac11d1d28 100644 --- a/compiler/testData/diagnostics/tests/collectionLiterals/defaultValuesInAnnotation.kt +++ b/compiler/testData/diagnostics/tests/collectionLiterals/defaultValuesInAnnotation.kt @@ -8,9 +8,9 @@ annotation class Foo( ) annotation class Bar( - val a: Array = [' '], + val a: Array = [' '], val b: Array = ["", ''], - val c: Array = [1] + val c: Array = [1] ) annotation class Base( @@ -22,5 +22,5 @@ annotation class Base( annotation class Err( val a: IntArray = [1L], - val b: Array = [1] + val b: Array = [1] ) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/delegation/DelegationExpectedType.kt b/compiler/testData/diagnostics/tests/delegation/DelegationExpectedType.kt index 2e237f6e3b3..6b1fb85839c 100644 --- a/compiler/testData/diagnostics/tests/delegation/DelegationExpectedType.kt +++ b/compiler/testData/diagnostics/tests/delegation/DelegationExpectedType.kt @@ -21,6 +21,6 @@ class D : A by baz({ it + 1 }) fun boo(t: T): A = AImpl() -class E : A by boo("") +class E : A by boo("") class F : A by AImpl() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/generics/innerClasses/innerTP.kt b/compiler/testData/diagnostics/tests/generics/innerClasses/innerTP.kt index a363c97b8fd..6719bcf122f 100644 --- a/compiler/testData/diagnostics/tests/generics/innerClasses/innerTP.kt +++ b/compiler/testData/diagnostics/tests/generics/innerClasses/innerTP.kt @@ -32,7 +32,7 @@ fun main() { checkSubtype.Inner<*>>(outer.Inner()) checkSubtype.Inner>(outer.bar()) - checkSubtype.Inner>(outer.Inner()) + checkSubtype.Inner>(outer.Inner()) outer.set(outer.bar()) outer.set(outer.Inner()) diff --git a/compiler/testData/diagnostics/tests/inference/capturedTypes/cannotCaptureInProjection.kt b/compiler/testData/diagnostics/tests/inference/capturedTypes/cannotCaptureInProjection.kt index 0fd1ed9274c..c5b21167335 100644 --- a/compiler/testData/diagnostics/tests/inference/capturedTypes/cannotCaptureInProjection.kt +++ b/compiler/testData/diagnostics/tests/inference/capturedTypes/cannotCaptureInProjection.kt @@ -5,13 +5,13 @@ fun bar(a: Array): Array = null!! fun test1(a: Array) { - val r: Array = bar(a) - bar(a) + val r: Array = bar(a) + bar(a) } fun foo(l: Array): Array> = null!! fun test2(a: Array) { - val r: Array> = foo(a) - foo(a) + val r: Array> = foo(a) + foo(a) } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/capturedTypes/captureTypeOnlyOnTopLevel.kt b/compiler/testData/diagnostics/tests/inference/capturedTypes/captureTypeOnlyOnTopLevel.kt index 3da1c1e0305..1330874b71a 100644 --- a/compiler/testData/diagnostics/tests/inference/capturedTypes/captureTypeOnlyOnTopLevel.kt +++ b/compiler/testData/diagnostics/tests/inference/capturedTypes/captureTypeOnlyOnTopLevel.kt @@ -4,7 +4,7 @@ fun foo(array: Array>): Array> = array fun test(array: Array>) { - foo(array) + foo(array) - val f: Array> = foo(array) + val f: Array> = foo(array) } diff --git a/compiler/testData/diagnostics/tests/inference/completion/kt33166.kt b/compiler/testData/diagnostics/tests/inference/completion/kt33166.kt index f2e008933fe..8697bc4408a 100644 --- a/compiler/testData/diagnostics/tests/inference/completion/kt33166.kt +++ b/compiler/testData/diagnostics/tests/inference/completion/kt33166.kt @@ -31,7 +31,7 @@ fun f1(future: OurFuture, e: Either.Left) { true -> OurFuture.createOurFuture(e) else -> throw Exception() } - x + x } } diff --git a/compiler/testData/diagnostics/tests/inference/constraints/kt6320.kt b/compiler/testData/diagnostics/tests/inference/constraints/kt6320.kt index b8db67946b0..7e5d332a515 100644 --- a/compiler/testData/diagnostics/tests/inference/constraints/kt6320.kt +++ b/compiler/testData/diagnostics/tests/inference/constraints/kt6320.kt @@ -16,6 +16,6 @@ class C class D(foo: C) { fun test(a: C) { - val d: D = D(a) + val d: D = D(a) } } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/dependantOnVariance.kt b/compiler/testData/diagnostics/tests/inference/dependantOnVariance.kt index 5a413f7a3fa..328611b1157 100644 --- a/compiler/testData/diagnostics/tests/inference/dependantOnVariance.kt +++ b/compiler/testData/diagnostics/tests/inference/dependantOnVariance.kt @@ -14,7 +14,7 @@ fun readFromMyList(l: MyList, = getMyList(int) - val a1 : MyList = getMyList(any) + val a1 : MyList = getMyList(any) val a2 : MyList = getMyList(int) diff --git a/compiler/testData/diagnostics/tests/inference/typeInferenceExpectedTypeMismatch.kt b/compiler/testData/diagnostics/tests/inference/typeInferenceExpectedTypeMismatch.kt index 8eb209a6b29..999c6a6a498 100644 --- a/compiler/testData/diagnostics/tests/inference/typeInferenceExpectedTypeMismatch.kt +++ b/compiler/testData/diagnostics/tests/inference/typeInferenceExpectedTypeMismatch.kt @@ -26,7 +26,7 @@ fun foo(o: Out, i: In): Two = throw Exception("$o $i") fun test1(outA: Out, inB: In) { foo(outA, inB) - val b: Two = foo(outA, inB) + val b: Two = foo(outA, inB) use(b) } @@ -35,7 +35,7 @@ fun bar(o: Out, i: In): Two = throw Exception("$o $i") fun test2(outA: Out, inC: In) { bar(outA, inC) - val b: Two = bar(outA, inC) + val b: Two = bar(outA, inC) use(b) } diff --git a/compiler/testData/diagnostics/tests/inference/upperBounds/useBoundsToInferTypeParamsSimple.kt b/compiler/testData/diagnostics/tests/inference/upperBounds/useBoundsToInferTypeParamsSimple.kt index 322568f2322..0ad0211a464 100644 --- a/compiler/testData/diagnostics/tests/inference/upperBounds/useBoundsToInferTypeParamsSimple.kt +++ b/compiler/testData/diagnostics/tests/inference/upperBounds/useBoundsToInferTypeParamsSimple.kt @@ -16,7 +16,7 @@ fun checkItIsExactlyAny(t: T, l baz(v: V, u: MutableSet) = u fun test(a: Any, s: MutableSet) { - baz(a, s) + baz(a, s) } //from standard library diff --git a/compiler/testData/diagnostics/tests/j+k/genericConstructor/classTypeParameterInferredFromArgument.kt b/compiler/testData/diagnostics/tests/j+k/genericConstructor/classTypeParameterInferredFromArgument.kt index 8d821cfe4d5..aaacea638de 100644 --- a/compiler/testData/diagnostics/tests/j+k/genericConstructor/classTypeParameterInferredFromArgument.kt +++ b/compiler/testData/diagnostics/tests/j+k/genericConstructor/classTypeParameterInferredFromArgument.kt @@ -12,6 +12,6 @@ fun test(x: List, y: List) { A("", x) checkType { _>() } A("", y) checkType { _>() } - A("", x) + A("", x) A("", y) } diff --git a/compiler/testData/diagnostics/tests/j+k/genericConstructor/innerClass.kt b/compiler/testData/diagnostics/tests/j+k/genericConstructor/innerClass.kt index 9a3c304ef35..9b45fba814c 100644 --- a/compiler/testData/diagnostics/tests/j+k/genericConstructor/innerClass.kt +++ b/compiler/testData/diagnostics/tests/j+k/genericConstructor/innerClass.kt @@ -14,5 +14,5 @@ fun test(x: List, y: List) { Outer().Inner("", y, 1) checkType { _.Inner>() } Outer().Inner("", x, 1) checkType { _.Inner>() } - Outer().Inner("", x, 1) + Outer().Inner("", x, 1) } diff --git a/compiler/testData/diagnostics/tests/j+k/genericConstructor/noClassTypeParametersInvParameter.kt b/compiler/testData/diagnostics/tests/j+k/genericConstructor/noClassTypeParametersInvParameter.kt index e5f2645fb36..f06758b278c 100644 --- a/compiler/testData/diagnostics/tests/j+k/genericConstructor/noClassTypeParametersInvParameter.kt +++ b/compiler/testData/diagnostics/tests/j+k/genericConstructor/noClassTypeParametersInvParameter.kt @@ -10,12 +10,12 @@ public class A { class Inv fun test(x: Inv, y: Inv) { - A("", x) + A("", x) A("", y) A("", x) - A("", x) + A("", x) A("", y) A("", y) } diff --git a/compiler/testData/diagnostics/tests/numbers/numbersInSimpleConstraints.kt b/compiler/testData/diagnostics/tests/numbers/numbersInSimpleConstraints.kt index 79588610cd3..4370e828990 100644 --- a/compiler/testData/diagnostics/tests/numbers/numbersInSimpleConstraints.kt +++ b/compiler/testData/diagnostics/tests/numbers/numbersInSimpleConstraints.kt @@ -44,7 +44,7 @@ interface Inv fun exactBound(t: T, l: Inv): T = throw Exception("$t $l") fun testExactBound(invS: Inv, invI: Inv, invB: Inv) { - exactBound(1, invS) + exactBound(1, invS) exactBound(1, invI) val b = exactBound(1, invB) diff --git a/compiler/testData/diagnostics/tests/regressions/kt35626.kt b/compiler/testData/diagnostics/tests/regressions/kt35626.kt new file mode 100644 index 00000000000..f301a0d0a37 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt35626.kt @@ -0,0 +1,24 @@ +// FIR_IDENTICAL +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class Result { + fun map(transform: (T) -> R): Result = TODO() +} + +class Tuple12( + val _1: T1, val _2: T2, val _3: T3, val _4: T4, val _5: T5, val _6: T6, + val _7: T7, val _8: T8, val _9: T9, val _10: T10, val _11: T11, val _12: T12, val _13: T13 +) + +fun rules12(res: Result): + Result> { + return res.map { + @Suppress("UNCHECKED_CAST") + Tuple12( + it as T1, it as T2, it as T3, it as T4, it as T5, it as T6, + it as T7, it as T8, it as T9, it as T10, it as T11, it as T12, it as T13 + ) + } +} + diff --git a/compiler/testData/diagnostics/tests/regressions/kt35626.txt b/compiler/testData/diagnostics/tests/regressions/kt35626.txt new file mode 100644 index 00000000000..4a346af99b8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt35626.txt @@ -0,0 +1,31 @@ +package + +public fun rules12(/*0*/ res: Result): Result> + +public final class Result { + public constructor Result() + 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 final fun map(/*0*/ transform: (T) -> R): Result + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Tuple12 { + public constructor Tuple12(/*0*/ _1: T1, /*1*/ _2: T2, /*2*/ _3: T3, /*3*/ _4: T4, /*4*/ _5: T5, /*5*/ _6: T6, /*6*/ _7: T7, /*7*/ _8: T8, /*8*/ _9: T9, /*9*/ _10: T10, /*10*/ _11: T11, /*11*/ _12: T12, /*12*/ _13: T13) + public final val _1: T1 + public final val _10: T10 + public final val _11: T11 + public final val _12: T12 + public final val _13: T13 + public final val _2: T2 + public final val _3: T3 + public final val _4: T4 + public final val _5: T5 + public final val _6: T6 + public final val _7: T7 + public final val _8: T8 + public final val _9: T9 + 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/tests/regressions/kt35626small.kt b/compiler/testData/diagnostics/tests/regressions/kt35626small.kt new file mode 100644 index 00000000000..6b49e3dbcd6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt35626small.kt @@ -0,0 +1,22 @@ +// FIR_IDENTICAL +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class Result { + fun map(transform: (T) -> R): Result = TODO() +} + +class TupleX( + val _1: T1, val _2: T2, val _3: T3, val _4: T4 +) + +fun rules(res: Result): + Result> { + return res.map { + @Suppress("UNCHECKED_CAST") + TupleX( + it as K1, it as K2, it as K3, it as K4 + ) + } +} + diff --git a/compiler/testData/diagnostics/tests/regressions/kt35626small.txt b/compiler/testData/diagnostics/tests/regressions/kt35626small.txt new file mode 100644 index 00000000000..5e431b9aff3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt35626small.txt @@ -0,0 +1,22 @@ +package + +public fun rules(/*0*/ res: Result): Result> + +public final class Result { + public constructor Result() + 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 final fun map(/*0*/ transform: (T) -> R): Result + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class TupleX { + public constructor TupleX(/*0*/ _1: T1, /*1*/ _2: T2, /*2*/ _3: T3, /*3*/ _4: T4) + public final val _1: T1 + public final val _2: T2 + public final val _3: T3 + public final val _4: T4 + 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/tests/resolve/invoke/errors/typeInferenceErrorForInvoke.kt b/compiler/testData/diagnostics/tests/resolve/invoke/errors/typeInferenceErrorForInvoke.kt index 4e079470edd..131f0c14783 100644 --- a/compiler/testData/diagnostics/tests/resolve/invoke/errors/typeInferenceErrorForInvoke.kt +++ b/compiler/testData/diagnostics/tests/resolve/invoke/errors/typeInferenceErrorForInvoke.kt @@ -8,7 +8,7 @@ operator fun T.invoke(a: A) {} fun foo(s: String, ai: A) { 1(ai) - s(ai) + s(ai) - ""(ai) + ""(ai) } diff --git a/compiler/testData/diagnostics/tests/resolve/specialConstructions/constantsInIf.kt b/compiler/testData/diagnostics/tests/resolve/specialConstructions/constantsInIf.kt index 2cabddea8fd..7679346bd45 100644 --- a/compiler/testData/diagnostics/tests/resolve/specialConstructions/constantsInIf.kt +++ b/compiler/testData/diagnostics/tests/resolve/specialConstructions/constantsInIf.kt @@ -8,7 +8,7 @@ fun test() { 2 }) - bar(1 ?: 2) + bar(1 ?: 2) } fun bar(s: String) = s \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/constructorCallType.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/constructorCallType.kt index 7a9faa105ec..013f49da8be 100644 --- a/compiler/testData/diagnostics/tests/secondaryConstructors/constructorCallType.kt +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/constructorCallType.kt @@ -21,7 +21,7 @@ val y4: B = B("") val y5: B = B(1) val y6: B = B("") -val y7: B = B(1) +val y7: B = B(1) val y8: B = B("") val y9 = B(1) diff --git a/compiler/testData/diagnostics/tests/smartCasts/inference/intersectionTypes.kt b/compiler/testData/diagnostics/tests/smartCasts/inference/intersectionTypes.kt index 1286554a1f7..8477a0bddb2 100644 --- a/compiler/testData/diagnostics/tests/smartCasts/inference/intersectionTypes.kt +++ b/compiler/testData/diagnostics/tests/smartCasts/inference/intersectionTypes.kt @@ -39,11 +39,11 @@ fun foo(t: T, l: MutableList): T = t fun testErrorMessages(a: A, ml: MutableList) { if (a is B && a is C) { - foo(a, ml) + foo(a, ml) } if(a is C) { - foo(a, ml) + foo(a, ml) } } diff --git a/compiler/testData/diagnostics/tests/typeParameters/implicitNothingInReturnPosition.kt b/compiler/testData/diagnostics/tests/typeParameters/implicitNothingInReturnPosition.kt index 5006759104e..c9b3c768423 100644 --- a/compiler/testData/diagnostics/tests/typeParameters/implicitNothingInReturnPosition.kt +++ b/compiler/testData/diagnostics/tests/typeParameters/implicitNothingInReturnPosition.kt @@ -40,7 +40,7 @@ class Context fun Any.decodeIn(typeFrom: Context): T = something() fun Any?.decodeOut1(typeFrom: Context): T { - return this?.decodeIn(typeFrom) ?: kotlin.Unit + return this?.decodeIn(typeFrom) ?: kotlin.Unit } fun Any.decodeOut2(typeFrom: Context): T { diff --git a/compiler/testData/diagnostics/tests/typealias/boundsViolationInDeepTypeAliasExpansion.kt b/compiler/testData/diagnostics/tests/typealias/boundsViolationInDeepTypeAliasExpansion.kt index d4592f5148e..fcf532a4be2 100644 --- a/compiler/testData/diagnostics/tests/typealias/boundsViolationInDeepTypeAliasExpansion.kt +++ b/compiler/testData/diagnostics/tests/typealias/boundsViolationInDeepTypeAliasExpansion.kt @@ -14,4 +14,4 @@ fun test4(x: TC2>() val test6 = TC2>() val test7 = TC2>() -val test8 = TC2List>() +val test8 = TC2List>() diff --git a/compiler/testData/diagnostics/tests/typealias/boundsViolationInTypeAliasExpansion.kt b/compiler/testData/diagnostics/tests/typealias/boundsViolationInTypeAliasExpansion.kt index 9526c950a20..df564a93c63 100644 --- a/compiler/testData/diagnostics/tests/typealias/boundsViolationInTypeAliasExpansion.kt +++ b/compiler/testData/diagnostics/tests/typealias/boundsViolationInTypeAliasExpansion.kt @@ -27,4 +27,4 @@ fun test12(x: TCList>) {} val test13 = TC>() val test14 = TC>() val test15 = TC>() -val test16 = TCList>() +val test16 = TCList>() diff --git a/compiler/testData/diagnostics/tests/typealias/noApproximationInTypeAliasArgumentSubstitution.kt b/compiler/testData/diagnostics/tests/typealias/noApproximationInTypeAliasArgumentSubstitution.kt index c5f8820b07f..00d8fc5e873 100644 --- a/compiler/testData/diagnostics/tests/typealias/noApproximationInTypeAliasArgumentSubstitution.kt +++ b/compiler/testData/diagnostics/tests/typealias/noApproximationInTypeAliasArgumentSubstitution.kt @@ -14,4 +14,4 @@ typealias TMap = Map fun foo2(m: TMap) = m fun bar2(m: TMap<*>) = - foo2(m) + foo2(m) diff --git a/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorTypeArgumentsInference.ni.txt b/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorTypeArgumentsInference.ni.txt index a9b012a6f4d..82524b39e19 100644 --- a/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorTypeArgumentsInference.ni.txt +++ b/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorTypeArgumentsInference.ni.txt @@ -6,9 +6,9 @@ public val test2: C /* = Cons */ public val test3: [ERROR : Type for CC(1, 2)] public val test4: CC /* = Cons> */ public val test5: PL /* = Pair> */ -public fun testProjections1(/*0*/ x: Pair): Foo -public fun testProjections2(/*0*/ x: Pair): Foo -public fun testProjections3(/*0*/ x: Pair): Foo +public fun testProjections1(/*0*/ x: Pair): Foo +public fun testProjections2(/*0*/ x: Pair): Foo +public fun testProjections3(/*0*/ x: Pair): Foo public fun testProjections4(/*0*/ x: Pair): Foo public final class Cons { diff --git a/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorTypeArgumentsInferenceWithNestedCalls.kt b/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorTypeArgumentsInferenceWithNestedCalls.kt index 0985a25df25..b7a04efa96a 100644 --- a/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorTypeArgumentsInferenceWithNestedCalls.kt +++ b/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorTypeArgumentsInferenceWithNestedCalls.kt @@ -5,4 +5,4 @@ class Cons(val head: T, val tail: Cons?) typealias C = Cons val test1 = C(1, C(2, null)) -val test2 = C(1, C("", null)) +val test2 = C(1, C("", null)) diff --git a/compiler/testData/diagnostics/tests/when/kt9972.kt b/compiler/testData/diagnostics/tests/when/kt9972.kt index 814813cabeb..787d04cbe47 100644 --- a/compiler/testData/diagnostics/tests/when/kt9972.kt +++ b/compiler/testData/diagnostics/tests/when/kt9972.kt @@ -10,7 +10,7 @@ fun test1(): Int { } fun test2(): Int { - val x: String = when { + val x: String = when { true -> Any() else -> null } ?: return 0 diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/kClass/kClassArrayInAnnotationsInVariance.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/kClass/kClassArrayInAnnotationsInVariance.kt index bc57ae7ff64..0183d191c53 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/annotations/kClass/kClassArrayInAnnotationsInVariance.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/kClass/kClassArrayInAnnotationsInVariance.kt @@ -14,7 +14,7 @@ class MyClass1 @Ann1(arrayOf(Any::class)) class MyClass1a -@Ann1(arrayOf(B1::class)) +@Ann1(arrayOf(B1::class)) class MyClass2 annotation class Ann2(val arg: Array>) @@ -25,5 +25,5 @@ class MyClass3 @Ann2(arrayOf(B1::class)) class MyClass4 -@Ann2(arrayOf(B2::class)) +@Ann2(arrayOf(B2::class)) class MyClass5 diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/kClass/kClassArrayInAnnotationsOutVariance.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/kClass/kClassArrayInAnnotationsOutVariance.kt index 121cfda3fe7..dc5ca411f21 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/annotations/kClass/kClassArrayInAnnotationsOutVariance.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/kClass/kClassArrayInAnnotationsOutVariance.kt @@ -11,7 +11,7 @@ annotation class Ann1(val arg: Array>) @Ann1(arrayOf(A::class)) class MyClass1 -@Ann1(arrayOf(Any::class)) +@Ann1(arrayOf(Any::class)) class MyClass1a @Ann1(arrayOf(B1::class)) @@ -19,11 +19,11 @@ class MyClass2 annotation class Ann2(val arg: Array>) -@Ann2(arrayOf(A::class)) +@Ann2(arrayOf(A::class)) class MyClass3 @Ann2(arrayOf(B1::class)) class MyClass4 -@Ann2(arrayOf(B2::class)) +@Ann2(arrayOf(B2::class)) class MyClass5 diff --git a/compiler/testData/diagnostics/testsWithStdLib/elvisOnJavaList.kt b/compiler/testData/diagnostics/testsWithStdLib/elvisOnJavaList.kt index 61ffc483cc5..5a339692f2f 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/elvisOnJavaList.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/elvisOnJavaList.kt @@ -15,5 +15,5 @@ public class P { fun foo(c: P): MutableList { // Error should be here: see KT-8168 Typechecker fails for platform collection type - return c.getList() ?: listOf() + return c.getList() ?: listOf() } \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/tryCatch/tryExpression.kt b/compiler/testData/diagnostics/testsWithStdLib/tryCatch/tryExpression.kt index 0406ad6da0d..25140a42cbc 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 ddddc19fe4d..7d8e44128b6 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -18086,6 +18086,16 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTestWithFirVali runTest("compiler/testData/diagnostics/tests/regressions/kt3535.kt"); } + @TestMetadata("kt35626.kt") + public void testKt35626() throws Exception { + runTest("compiler/testData/diagnostics/tests/regressions/kt35626.kt"); + } + + @TestMetadata("kt35626small.kt") + public void testKt35626small() throws Exception { + runTest("compiler/testData/diagnostics/tests/regressions/kt35626small.kt"); + } + @TestMetadata("kt35668.kt") public void testKt35668() throws Exception { runTest("compiler/testData/diagnostics/tests/regressions/kt35668.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java index b15c013594b..15a5a000159 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java @@ -18076,6 +18076,16 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing runTest("compiler/testData/diagnostics/tests/regressions/kt3535.kt"); } + @TestMetadata("kt35626.kt") + public void testKt35626() throws Exception { + runTest("compiler/testData/diagnostics/tests/regressions/kt35626.kt"); + } + + @TestMetadata("kt35626small.kt") + public void testKt35626small() throws Exception { + runTest("compiler/testData/diagnostics/tests/regressions/kt35626small.kt"); + } + @TestMetadata("kt35668.kt") public void testKt35668() throws Exception { runTest("compiler/testData/diagnostics/tests/regressions/kt35668.kt"); diff --git a/j2k/testData/fileOrElement/typeParameters/rawTypeCast.kt b/j2k/testData/fileOrElement/typeParameters/rawTypeCast.kt index 5379d45dc09..59e8720a1c5 100644 --- a/j2k/testData/fileOrElement/typeParameters/rawTypeCast.kt +++ b/j2k/testData/fileOrElement/typeParameters/rawTypeCast.kt @@ -1,5 +1,6 @@ // ERROR: Type mismatch: inferred type is (Any?..Any?) but String! was expected // ERROR: Type mismatch: inferred type is (Any?..Any?) but String! was expected +// ERROR: Type mismatch: inferred type is (Any?..Any?) but String! was expected // ERROR: Type mismatch: inferred type is HashMap but Map was expected import java.util.* diff --git a/nj2k/testData/newJ2k/toArray/toArray.kt b/nj2k/testData/newJ2k/toArray/toArray.kt index 9759ed5761d..7477d3929a2 100644 --- a/nj2k/testData/newJ2k/toArray/toArray.kt +++ b/nj2k/testData/newJ2k/toArray/toArray.kt @@ -1,5 +1,4 @@ // ERROR: Type mismatch: inferred type is Any but String was expected -// ERROR: Type mismatch: inferred type is Any but String was expected // ERROR: Type mismatch: inferred type is Array but Array was expected import java.util.Arrays diff --git a/nj2k/testData/newJ2k/typeParameters/rawTypeCast.kt b/nj2k/testData/newJ2k/typeParameters/rawTypeCast.kt index 17d383b6020..a58cc7887d5 100644 --- a/nj2k/testData/newJ2k/typeParameters/rawTypeCast.kt +++ b/nj2k/testData/newJ2k/typeParameters/rawTypeCast.kt @@ -2,6 +2,8 @@ // ERROR: Type mismatch: inferred type is (Any?..Any?) but String? was expected // ERROR: Type mismatch: inferred type is Any! but String? was expected // ERROR: Type mismatch: inferred type is (Any?..Any?) but String? was expected +// ERROR: Type mismatch: inferred type is Any! but String? was expected +// ERROR: Type mismatch: inferred type is (Any?..Any?) but String? was expected // ERROR: Type mismatch: inferred type is HashMap but Map was expected import java.util.HashMap import java.util.Properties