diff --git a/compiler/container/src/org/jetbrains/kotlin/container/Cache.kt b/compiler/container/src/org/jetbrains/kotlin/container/Cache.kt index 0ce45792cee..9a663cf4e74 100644 --- a/compiler/container/src/org/jetbrains/kotlin/container/Cache.kt +++ b/compiler/container/src/org/jetbrains/kotlin/container/Cache.kt @@ -77,12 +77,10 @@ private fun getConstructorInfo(c: Class<*>): ConstructorInfo? { if (Modifier.isAbstract(c.modifiers) || c.isPrimitive) return null - val constructors = c.constructors - val hasSinglePublicConstructor = constructors.singleOrNull()?.let { Modifier.isPublic(it.modifiers) } ?: false - if (!hasSinglePublicConstructor) - return null + val publicConstructors = c.constructors.filter { Modifier.isPublic(it.modifiers) && !it.isSynthetic } + if (publicConstructors.size != 1) return null - val constructor = constructors.single() + val constructor = publicConstructors.single() val parameterTypes = if (c.declaringClass != null && !Modifier.isStatic(c.modifiers)) listOf(c.declaringClass, *constructor.genericParameterTypes) @@ -126,4 +124,4 @@ private fun getRegistrations(klass: Class<*>): List { registrations.addAll(interfaces) registrations.remove(Any::class.java) return registrations -} \ No newline at end of file +} diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/InferenceUtil.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/InferenceUtil.kt index 27c13fb8f26..4f7966e2e64 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/InferenceUtil.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/InferenceUtil.kt @@ -51,7 +51,7 @@ class InferenceComponents( return ConeClassErrorType(message) } } - val trivialConstraintTypeInferenceOracle = TrivialConstraintTypeInferenceOracle(ctx) + val trivialConstraintTypeInferenceOracle = TrivialConstraintTypeInferenceOracle.create(ctx) private val incorporator = ConstraintIncorporator(approximator, trivialConstraintTypeInferenceOracle) private val injector = ConstraintInjector(incorporator, approximator, KotlinTypeRefiner.Default) val resultTypeResolver = ResultTypeResolver(approximator, trivialConstraintTypeInferenceOracle) diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/TrivialConstraintTypeInferenceOracle.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/TrivialConstraintTypeInferenceOracle.kt index 46b0f14ac2f..2174c009a62 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/TrivialConstraintTypeInferenceOracle.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/TrivialConstraintTypeInferenceOracle.kt @@ -11,8 +11,11 @@ import org.jetbrains.kotlin.types.model.KotlinTypeMarker import org.jetbrains.kotlin.types.model.TypeSystemInferenceExtensionContext import org.jetbrains.kotlin.types.model.TypeSystemInferenceExtensionContextDelegate -class TrivialConstraintTypeInferenceOracle(context: TypeSystemInferenceExtensionContextDelegate) : +class TrivialConstraintTypeInferenceOracle private constructor(context: TypeSystemInferenceExtensionContext) : TypeSystemInferenceExtensionContext by context { + // This constructor is used for injection only in old FE + constructor(context: TypeSystemInferenceExtensionContextDelegate) : this(context as TypeSystemInferenceExtensionContext) + // The idea is to add knowledge that constraint `Nothing(?) <: T` is quite useless and // it's totally fine to go and resolve postponed argument without fixation T to Nothing(?). // In other words, constraint `Nothing(?) <: T` is *not* proper @@ -62,4 +65,8 @@ class TrivialConstraintTypeInferenceOracle(context: TypeSystemInferenceExtension private fun KotlinTypeMarker.containsOnlyNonNullableNothing(): Boolean = contains { it.isNothing() } && !contains { it.isNullableNothing() } + + companion object { + fun create(context: TypeSystemInferenceExtensionContext) = TrivialConstraintTypeInferenceOracle(context) + } } diff --git a/core/type-system/src/org/jetbrains/kotlin/types/model/TypeSystemContext.kt b/core/type-system/src/org/jetbrains/kotlin/types/model/TypeSystemContext.kt index aaca404a786..69cf6c675cc 100644 --- a/core/type-system/src/org/jetbrains/kotlin/types/model/TypeSystemContext.kt +++ b/core/type-system/src/org/jetbrains/kotlin/types/model/TypeSystemContext.kt @@ -105,6 +105,10 @@ interface TypeSystemCommonSuperTypesContext : TypeSystemContext, TypeSystemTypeF fun TypeConstructorMarker.toErrorType(): SimpleTypeMarker } +// This interface is only used to declare that implementing class is supposed to be used as a TypeSystemInferenceExtensionContext component +// Otherwise clash happens during DI container initialization: there are a lot of components that extend TypeSystemInferenceExtensionContext +// but they only has it among supertypes to bring additional receiver into their scopes, i.e. they are not intended to be used as +// component implementation for TypeSystemInferenceExtensionContext interface TypeSystemInferenceExtensionContextDelegate : TypeSystemInferenceExtensionContext interface TypeSystemInferenceExtensionContext : TypeSystemContext, TypeSystemBuiltInsContext, TypeSystemCommonSuperTypesContext {