diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/resolveWithOnlyInputTypesAnnotation.kt b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/resolveWithOnlyInputTypesAnnotation.kt index e892898c94a..b904554b4f7 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/resolveWithOnlyInputTypesAnnotation.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/resolveWithOnlyInputTypesAnnotation.kt @@ -11,4 +11,11 @@ class D fun test1(a: A, b: B, c: C) { assertEquals1(a, b) assertEquals1(b, c) +} + +@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") +public fun <@kotlin.internal.OnlyInputTypes T> expect1(expected: T, block: () -> T) {} + +fun test() { + expect1(2) { byteArrayOf(1, 2, 3).indexOf(3) } } \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/resolveWithOnlyInputTypesAnnotation.txt b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/resolveWithOnlyInputTypesAnnotation.txt index ab366501ef7..325b223d2a9 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/resolveWithOnlyInputTypesAnnotation.txt +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/resolveWithOnlyInputTypesAnnotation.txt @@ -1,6 +1,8 @@ package @kotlin.Suppress(names = {"INVISIBLE_MEMBER", "INVISIBLE_REFERENCE"}) public fun assertEquals1(/*0*/ t1: T, /*1*/ t2: T): kotlin.Unit +@kotlin.Suppress(names = {"INVISIBLE_MEMBER", "INVISIBLE_REFERENCE"}) public fun expect1(/*0*/ expected: T, /*1*/ block: () -> T): kotlin.Unit +public fun test(): kotlin.Unit public fun test1(/*0*/ a: A, /*1*/ b: B, /*2*/ c: C): kotlin.Unit public open class A { diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/calls/inference/ConstraintSystemImpl.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/calls/inference/ConstraintSystemImpl.kt index a5a19934a6e..aeec7425cdb 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/calls/inference/ConstraintSystemImpl.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/resolve/calls/inference/ConstraintSystemImpl.kt @@ -84,13 +84,14 @@ public class ConstraintSystemImpl : ConstraintSystem { override fun hasContradiction() = hasParameterConstraintError() || hasConflictingConstraints() || hasCannotCaptureTypesError() || hasTypeInferenceIncorporationError() - || hasTypeParameterWithUnsatisfiedOnlyInputTypesError() + override fun hasViolatedUpperBound() = !isSuccessful() && filterConstraintsOut(TYPE_BOUND_POSITION).getStatus().isSuccessful() override fun hasConflictingConstraints() = localTypeParameterBounds.values().any { it.values.size() > 1 } - override fun hasUnknownParameters() = localTypeParameterBounds.values().any { it.values.isEmpty() } + override fun hasUnknownParameters() = + localTypeParameterBounds.values().any { it.values.isEmpty() } || hasTypeParameterWithUnsatisfiedOnlyInputTypesError() override fun hasParameterConstraintError() = errors.any { it is ParameterConstraintError } diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/calls/inference/TypeBoundsImpl.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/calls/inference/TypeBoundsImpl.kt index dcf8f716105..48331ae483b 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/calls/inference/TypeBoundsImpl.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/resolve/calls/inference/TypeBoundsImpl.kt @@ -36,10 +36,6 @@ public class TypeBoundsImpl( ) : TypeBounds { override val bounds = ArrayList() - private val typesInBoundsSet: Set by lazy { - bounds.filter { it.isProper }.map { it.constrainingType }.toSet() - } - private var resultValues: Collection? = null var isFixed: Boolean = false @@ -157,7 +153,10 @@ public class TypeBoundsImpl( // a captured type might be an answer if (!possibleAnswer.getConstructor().isDenotable() && !possibleAnswer.isCaptured()) return false - if (typeVariable.hasOnlyInputTypesAnnotation() && !typesInBoundsSet.contains(possibleAnswer)) return false + if (typeVariable.hasOnlyInputTypesAnnotation()) { + val typesInBoundsSet = bounds.filter { it.isProper && it.constrainingType.constructor.isDenotable }.map { it.constrainingType }.toSet() + if (!typesInBoundsSet.contains(possibleAnswer)) return false + } for (bound in bounds) { when (bound.kind) {