diff --git a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/VariableFixationFinder.kt b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/VariableFixationFinder.kt index 27ec88c4f39..91bb087104c 100644 --- a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/VariableFixationFinder.kt +++ b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/VariableFixationFinder.kt @@ -141,8 +141,12 @@ class VariableFixationFinder( return false } - private fun Context.variableHasProperArgumentConstraints(variable: TypeConstructorMarker): Boolean = - notFixedTypeVariables[variable]?.constraints?.any { isProperArgumentConstraint(it) } ?: false + private fun Context.variableHasProperArgumentConstraints(variable: TypeConstructorMarker): Boolean { + val constraints = notFixedTypeVariables[variable]?.constraints ?: return false + // temporary hack to fail calls which contain callable references resolved though OI with uninferred type parameters + val areThereConstraintsWithUninferredTypeParameter = constraints.any { c -> c.type.contains { it.isUninferredParameter() } } + return constraints.any { isProperArgumentConstraint(it) } && !areThereConstraintsWithUninferredTypeParameter + } private fun Context.isProperArgumentConstraint(c: Constraint) = isProperType(c.type) @@ -167,7 +171,7 @@ inline fun TypeSystemInferenceExtensionContext.isProperTypeForFixation( type: KotlinTypeMarker, isProper: (KotlinTypeMarker) -> Boolean ): Boolean { - if (!isProper(type) || type.contains { it.isUninferredParameter() }) return false + if (!isProper(type)) return false if (type.isCapturedType()) { val projection = (type as? SimpleTypeMarker)?.asCapturedType()?.typeConstructorProjection() ?: return true if (projection.isStarProjection()) return true diff --git a/compiler/testData/codegen/box/inference/builderInference/specialCallsWithLambdas.kt b/compiler/testData/codegen/box/inference/builderInference/specialCallsWithLambdas.kt index c9a7f6ff984..831e28658cc 100644 --- a/compiler/testData/codegen/box/inference/builderInference/specialCallsWithLambdas.kt +++ b/compiler/testData/codegen/box/inference/builderInference/specialCallsWithLambdas.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// IGNORE_BACKEND_FIR: JVM_IR import kotlin.experimental.ExperimentalTypeInference diff --git a/compiler/testData/codegen/box/inference/specialCallsWithCallableReferences.kt b/compiler/testData/codegen/box/inference/specialCallsWithCallableReferences.kt index be48cfab68d..56b57fa7ce8 100644 --- a/compiler/testData/codegen/box/inference/specialCallsWithCallableReferences.kt +++ b/compiler/testData/codegen/box/inference/specialCallsWithCallableReferences.kt @@ -32,12 +32,6 @@ fun poll16(flag: Boolean): Any? { return inv() } -// TODO -//fun poll17(flag: Boolean): Any? { -// val inv = if (flag) { foo7() } else { ::Foo7 } -// return inv -//} - fun poll21(flag: Boolean): Any? { val inv = when (flag) { true -> ::bar2 else -> ::foo2 } return inv() @@ -48,12 +42,6 @@ fun poll25(flag: Boolean): Any? { return inv } -// TODO -//fun poll26(flag: Boolean): Any? { -// val inv = when (flag) { true -> ::Foo7 false -> foo7() else -> ::Foo7 } -// return inv -//} - fun poll31(flag: Boolean): Any? { val inv = when (flag) { true -> ::bar2 false -> ::foo2 } return inv() @@ -64,12 +52,6 @@ fun poll35(flag: Boolean): Any? { return inv } -// TODO -//fun poll36(flag: Boolean): Any? { -// val inv = when (flag) { true -> ::Foo7 false -> foo7() } -// return inv -//} - fun poll41(): Any? { val inv = try { ::bar2 } finally { ::foo2 } return inv() @@ -90,12 +72,6 @@ fun poll55(): Any? { return inv() } -// TODO -//fun poll56(): Any? { -// val inv = try { ::Foo7 } catch (e: Exception) { foo7() } finally { foo7() } -// return inv -//} - fun poll61(): Any? { val inv = ::bar2 return inv @@ -121,7 +97,6 @@ fun poll81(): Any? { return inv } - fun poll85(): Any? { val inv = ::Foo6 in setOf(::Foo6) return inv @@ -131,18 +106,14 @@ fun box(): String { poll1(true) poll11(true) poll16(true) -// poll17(true) poll21(true) poll25(true) -// poll26(true) poll31(true) poll35(true) -// poll36(true) poll41() poll45() poll51() poll55() -// poll56() poll61() poll65() poll71() diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/specialCallsWithCallableReferences.kt b/compiler/testData/diagnostics/tests/inference/builderInference/specialCallsWithCallableReferences.kt index 1bf84cc30a8..ad9b44a3dc4 100644 --- a/compiler/testData/diagnostics/tests/inference/builderInference/specialCallsWithCallableReferences.kt +++ b/compiler/testData/diagnostics/tests/inference/builderInference/specialCallsWithCallableReferences.kt @@ -136,8 +136,8 @@ fun poll16(flag: Boolean): Flow { fun poll17(flag: Boolean): Flow { return flow { - val inv = if (flag) { foo7() } else { ::Foo7 } - inv + val inv = if (flag) { foo7() } else { ::Foo7 } + inv } } @@ -185,7 +185,7 @@ fun poll25(flag: Boolean): Flow { fun poll26(flag: Boolean): Flow { return flow { - val inv = when (flag) { true -> ::Foo7 false -> foo7() else -> ::Foo7 } + val inv = when (flag) { true -> ::Foo7 false -> foo7() else -> ::Foo7 } inv } } @@ -234,7 +234,7 @@ fun poll35(flag: Boolean): Flow { fun poll36(flag: Boolean): Flow { return flow { - val inv = when (flag) { true -> ::Foo7 false -> foo7() } + val inv = when (flag) { true -> ::Foo7 false -> foo7() } inv } } @@ -332,8 +332,8 @@ fun poll55(): Flow { fun poll56(): Flow { return flow { - val inv = try { ::Foo7 } catch (e: Exception) { foo7() } finally { foo7() } - inv + val inv = try { ::Foo7 } catch (e: Exception) { foo7() } finally { foo7() } + inv } } diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/specialCallsWithCallableReferencesDontCareTypeInBlockExression.kt b/compiler/testData/diagnostics/tests/inference/builderInference/specialCallsWithCallableReferencesDontCareTypeInBlockExression.kt index e87e69c10a7..fbf0f6f9699 100644 --- a/compiler/testData/diagnostics/tests/inference/builderInference/specialCallsWithCallableReferencesDontCareTypeInBlockExression.kt +++ b/compiler/testData/diagnostics/tests/inference/builderInference/specialCallsWithCallableReferencesDontCareTypeInBlockExression.kt @@ -85,8 +85,8 @@ fun poll16(flag: Boolean): Flow { fun poll17(flag: Boolean): Flow { return flow { - val inv = if (flag) { foo7() } else { ::Foo7 } - inv + val inv = if (flag) { foo7() } else { ::Foo7 } + inv } } @@ -183,7 +183,7 @@ fun poll55(): Flow { fun poll56(): Flow { return flow { - val inv = try { ::Foo7 } catch (e: Exception) { foo7() } finally { foo7() } - inv + val inv = try { ::Foo7 } catch (e: Exception) { foo7() } finally { foo7() } + inv } } diff --git a/compiler/testData/diagnostics/tests/inference/reportNotEnoughTypeInformationErrorsOnBlockExpressions.kt b/compiler/testData/diagnostics/tests/inference/reportNotEnoughTypeInformationErrorsOnBlockExpressions.kt index d98af6dcace..7db303c5969 100644 --- a/compiler/testData/diagnostics/tests/inference/reportNotEnoughTypeInformationErrorsOnBlockExpressions.kt +++ b/compiler/testData/diagnostics/tests/inference/reportNotEnoughTypeInformationErrorsOnBlockExpressions.kt @@ -9,8 +9,8 @@ class Foo7 fun foo7() = null as Foo7 fun poll17(flag: Boolean): Any? { - val inv = if (flag) { foo7() } else { ::Foo7 } - return inv + val inv = if (flag) { foo7() } else { ::Foo7 } + return inv } fun poll26(flag: Boolean): Any? { @@ -24,6 +24,6 @@ fun poll36(flag: Boolean): Any? { } fun poll56(): Any? { - val inv = try { ::Foo7 } catch (e: Exception) { foo7() } finally { foo7() } - return inv + val inv = try { ::Foo7 } catch (e: Exception) { foo7() } finally { foo7() } + return inv } diff --git a/compiler/testData/diagnostics/tests/inference/reportingImprovements/kt42620.kt b/compiler/testData/diagnostics/tests/inference/reportingImprovements/kt42620.kt index 66cd0c6cbae..04b2d5c3703 100644 --- a/compiler/testData/diagnostics/tests/inference/reportingImprovements/kt42620.kt +++ b/compiler/testData/diagnostics/tests/inference/reportingImprovements/kt42620.kt @@ -3,10 +3,10 @@ class Foo fun main1() = when { - else -> Foo::plus + else -> Foo::plus } -fun main2() = if (true) Foo::minus else Foo::times +fun main2() = if (true) Foo::minus else Foo::times fun main3() = if (true) { Foo::minus } else { Foo::times } diff --git a/compiler/testData/diagnostics/tests/inference/specialCallsWithCallableReferences.kt b/compiler/testData/diagnostics/tests/inference/specialCallsWithCallableReferences.kt index dc153a98e5b..2ee1eebab8f 100644 --- a/compiler/testData/diagnostics/tests/inference/specialCallsWithCallableReferences.kt +++ b/compiler/testData/diagnostics/tests/inference/specialCallsWithCallableReferences.kt @@ -54,8 +54,8 @@ fun poll16(flag: Boolean) { } fun poll17(flag: Boolean) { - val inv = if (flag) { foo7() } else { ::Foo7 } - inv + val inv = if (flag) { foo7() } else { ::Foo7 } + inv } fun poll2(flag: Boolean) { @@ -89,7 +89,7 @@ fun poll25(flag: Boolean) { } fun poll26(flag: Boolean) { - val inv = when (flag) { true -> ::Foo7 false -> foo7() else -> ::Foo7 } + val inv = when (flag) { true -> ::Foo7 false -> foo7() else -> ::Foo7 } inv } @@ -124,7 +124,7 @@ fun poll35(flag: Boolean) { } fun poll36(flag: Boolean) { - val inv = when (flag) { true -> ::Foo7 false -> foo7() } + val inv = when (flag) { true -> ::Foo7 false -> foo7() } inv } @@ -194,8 +194,8 @@ fun poll55() { } fun poll56() { - val inv = try { ::Foo7 } catch (e: Exception) { foo7() } finally { foo7() } - inv + val inv = try { ::Foo7 } catch (e: Exception) { foo7() } finally { foo7() } + inv } fun poll6() {