diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/KotlinCallCompleter.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/KotlinCallCompleter.kt index 50a5599a66f..36ac1aab449 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/KotlinCallCompleter.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/KotlinCallCompleter.kt @@ -19,6 +19,7 @@ import org.jetbrains.kotlin.types.UnwrappedType import org.jetbrains.kotlin.types.model.TypeSystemInferenceExtensionContext import org.jetbrains.kotlin.types.model.isIntegerLiteralTypeConstructor import org.jetbrains.kotlin.types.model.typeConstructor +import org.jetbrains.kotlin.types.typeUtil.contains class KotlinCallCompleter( private val postponedArgumentsAnalyzer: PostponedArgumentsAnalyzer, @@ -197,10 +198,27 @@ class KotlinCallCompleter( else ConstraintSystemCompletionMode.PARTIAL + // Return type has proper equal constraints => there is no need in the outer call + containsTypeVariablesWithProperEqualConstraints(currentReturnType) -> ConstraintSystemCompletionMode.FULL + else -> ConstraintSystemCompletionMode.PARTIAL } } + private fun KotlinResolutionCandidate.containsTypeVariablesWithProperEqualConstraints(type: UnwrappedType): Boolean { + for ((variableConstructor, variableWithConstraints) in csBuilder.currentStorage().notFixedTypeVariables) { + if (!type.contains { it.constructor == variableConstructor }) continue + + val constraints = variableWithConstraints.constraints + val onlyProperEqualConstraints = + constraints.isNotEmpty() && constraints.all { it.kind.isEqual() && csBuilder.isProperType(it.type) } + + if (!onlyProperEqualConstraints) return false + } + + return true + } + private fun KotlinResolutionCandidate.hasProperNonTrivialLowerConstraints(typeVariable: UnwrappedType): Boolean { assert(csBuilder.isTypeVariable(typeVariable)) { "$typeVariable is not a type variable" } diff --git a/compiler/testData/diagnostics/tests/controlStructures/ifElseIntersection.kt b/compiler/testData/diagnostics/tests/controlStructures/ifElseIntersection.kt index c9565393ff3..5657897fb70 100644 --- a/compiler/testData/diagnostics/tests/controlStructures/ifElseIntersection.kt +++ b/compiler/testData/diagnostics/tests/controlStructures/ifElseIntersection.kt @@ -25,7 +25,7 @@ fun bind2(r: Option): Option { } fun bind3(r: Option): Option { - return if (r is Some) { + return if (r is Some) { // Diagnoses an error correctly if (true) None() else r } diff --git a/compiler/testData/diagnostics/tests/generics/nullability/tpBoundsViolationVariance.kt b/compiler/testData/diagnostics/tests/generics/nullability/tpBoundsViolationVariance.kt index 9525eb00ecf..dd1e245e7a5 100644 --- a/compiler/testData/diagnostics/tests/generics/nullability/tpBoundsViolationVariance.kt +++ b/compiler/testData/diagnostics/tests/generics/nullability/tpBoundsViolationVariance.kt @@ -18,9 +18,9 @@ class A { fun bar() { // F fooInv1>(Inv()) - fooInv2<Inv>(Inv()) + fooInv2<Inv>(Inv()) fooInv1(Inv()) - fooInv2(Inv()) + fooInv2(Inv()) fooIn1>(In()) fooIn2>(In()) @@ -33,15 +33,15 @@ class A { fooOut2(Out()) // Z - fooInv1<Inv>(Inv()) - fooInv2<Inv>(Inv()) - fooInv1(Inv()) - fooInv2(Inv()) + fooInv1<Inv>(Inv()) + fooInv2<Inv>(Inv()) + fooInv1(Inv()) + fooInv2(Inv()) - fooIn1<In>(In()) - fooIn2<In>(In()) - fooIn1(In()) - fooIn2(In()) + fooIn1<In>(In()) + fooIn2<In>(In()) + fooIn1(In()) + fooIn2(In()) fooOut1>(Out()) fooOut2>(Out()) @@ -49,19 +49,19 @@ class A { fooOut2(Out()) // W - fooInv1<Inv>(Inv()) - fooInv2<Inv>(Inv()) - fooInv1(Inv()) - fooInv2(Inv()) + fooInv1<Inv>(Inv()) + fooInv2<Inv>(Inv()) + fooInv1(Inv()) + fooInv2(Inv()) - fooIn1<In>(In()) - fooIn2<In>(In()) - fooIn1(In()) - fooIn2(In()) + fooIn1<In>(In()) + fooIn2<In>(In()) + fooIn1(In()) + fooIn2(In()) - fooOut1<Out>(Out()) + fooOut1<Out>(Out()) fooOut2>(Out()) - fooOut1(Out()) + fooOut1(Out()) fooOut2(Out()) } } diff --git a/compiler/testData/diagnostics/tests/generics/projectionsScope/typeParameterBounds.kt b/compiler/testData/diagnostics/tests/generics/projectionsScope/typeParameterBounds.kt index 6ec1d9b2362..b839c0e9fbb 100644 --- a/compiler/testData/diagnostics/tests/generics/projectionsScope/typeParameterBounds.kt +++ b/compiler/testData/diagnostics/tests/generics/projectionsScope/typeParameterBounds.kt @@ -13,14 +13,14 @@ class A { } fun foo2(a: A, b: A) { - a.foo1(Out()) + a.foo1(Out()) a.foo1<Out>(Out()) a.foo1(Out()) a.foo1(Out()) a.foo2(Inv()) - a.foo2(Inv()) + a.foo2(Inv()) a.foo2<Inv>(Inv()) a.foo3(In()) @@ -32,11 +32,11 @@ fun foo2(a: A, b: A) { b.foo1>(Out()) b.foo2(Inv()) - b.foo2(Inv()) + b.foo2(Inv()) b.foo2<Inv>(Inv()) - b.foo3(In()) + b.foo3(In()) b.foo3<In>(In()) b.foo3(In()) diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/propagationOfNoInferAnnotation.kt b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/propagationOfNoInferAnnotation.kt index 31f95ce131f..7f7e91045c1 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/propagationOfNoInferAnnotation.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/propagationOfNoInferAnnotation.kt @@ -1,10 +1,25 @@ // !DIAGNOSTICS: -UNUSED_PARAMETER -@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") -fun foo(): @kotlin.internal.NoInfer T = TODO() +private object TopLevelTypeVariable { + @Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") + fun foo(): @kotlin.internal.NoInfer T = TODO() -fun bar(k: K) {} + fun bar(k: K) {} -fun test() { - bar(foo()) + fun test() { + bar(foo()) + } +} + +private object NestedTypeVariable { + class Inv + + @Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") + fun foo(): Inv<@kotlin.internal.NoInfer T> = TODO() + + fun bar(p: Inv) {} + + fun test() { + bar(foo()) + } } \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/propagationOfNoInferAnnotation.txt b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/propagationOfNoInferAnnotation.txt index 91de405288e..a241563812e 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/propagationOfNoInferAnnotation.txt +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/propagationOfNoInferAnnotation.txt @@ -1,5 +1,28 @@ package -public fun bar(/*0*/ k: K): kotlin.Unit -@kotlin.Suppress(names = {"INVISIBLE_MEMBER", "INVISIBLE_REFERENCE"}) public fun foo(): T -public fun test(): kotlin.Unit +private object NestedTypeVariable { + private constructor NestedTypeVariable() + public final fun bar(/*0*/ p: NestedTypeVariable.Inv): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + @kotlin.Suppress(names = {"INVISIBLE_MEMBER", "INVISIBLE_REFERENCE"}) public final fun foo(): NestedTypeVariable.Inv + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final fun test(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + public final class Inv { + public constructor 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 + } +} + +private object TopLevelTypeVariable { + private constructor TopLevelTypeVariable() + public final fun bar(/*0*/ k: K): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + @kotlin.Suppress(names = {"INVISIBLE_MEMBER", "INVISIBLE_REFERENCE"}) public final fun foo(): T + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final fun test(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java index 146a6a8e0fe..8c2e7b8364c 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java @@ -2748,6 +2748,11 @@ public class DiagnosticsTestWithStdLibGenerated extends AbstractDiagnosticsTestW runTest("compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/onlyInputTypesAnnotationWithPlatformTypes.kt"); } + @TestMetadata("propagationOfNoInferAnnotation.kt") + public void testPropagationOfNoInferAnnotation() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/propagationOfNoInferAnnotation.kt"); + } + @TestMetadata("resolveWithOnlyInputTypesAnnotation.kt") public void testResolveWithOnlyInputTypesAnnotation() throws Exception { runTest("compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/resolveWithOnlyInputTypesAnnotation.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java index d8b2272a3c4..556f1b8ce29 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java @@ -2748,6 +2748,11 @@ public class DiagnosticsTestWithStdLibUsingJavacGenerated extends AbstractDiagno runTest("compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/onlyInputTypesAnnotationWithPlatformTypes.kt"); } + @TestMetadata("propagationOfNoInferAnnotation.kt") + public void testPropagationOfNoInferAnnotation() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/propagationOfNoInferAnnotation.kt"); + } + @TestMetadata("resolveWithOnlyInputTypesAnnotation.kt") public void testResolveWithOnlyInputTypesAnnotation() throws Exception { runTest("compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/resolveWithOnlyInputTypesAnnotation.kt"); diff --git a/nj2k/src/org/jetbrains/kotlin/nj2k/tree/tokens.kt b/nj2k/src/org/jetbrains/kotlin/nj2k/tree/tokens.kt index 2870a85ed4d..3d276c6df70 100644 --- a/nj2k/src/org/jetbrains/kotlin/nj2k/tree/tokens.kt +++ b/nj2k/src/org/jetbrains/kotlin/nj2k/tree/tokens.kt @@ -33,7 +33,7 @@ fun JKNonCodeElementsListOwner.takeNonCodeElementsFrom(other: JKNonCodeElementsL fun JKTreeElement.commentsFromInside(): List { val comments = mutableListOf() fun recurse(element: JKTreeElement): JKTreeElement { - comments += (element.leftNonCodeElements + element.rightNonCodeElements).filterIsInstance() + comments += (element.leftNonCodeElements + element.rightNonCodeElements).filterIsInstance() return applyRecursive(element, ::recurse) } applyRecursive(this, ::recurse)