K1: report swallowed diagnostic about upper bound violation

#KT-55055 Fixed
This commit is contained in:
Mikhail Glukhikh
2023-02-06 09:30:14 +01:00
committed by Space Team
parent b148df15a9
commit 930237b60e
15 changed files with 90 additions and 5 deletions
@@ -39,6 +39,7 @@ class CallableReferenceArgumentResolver(val callableReferenceOverloadConflictRes
if (chosenCandidate != null) {
val toFreshSubstitutor = CreateFreshVariablesSubstitutor.createToFreshVariableSubstitutorAndAddInitialConstraints(
chosenCandidate.candidate,
resolvedAtom.atom.call,
csBuilder
)
chosenCandidate.addConstraints(csBuilder, toFreshSubstitutor, callableReference = argument)
@@ -124,7 +124,7 @@ internal object CreateFreshVariablesSubstitutor : ResolutionPart() {
if (candidateDescriptor.typeParameters.isEmpty())
FreshVariableNewTypeSubstitutor.Empty
else
createToFreshVariableSubstitutorAndAddInitialConstraints(candidateDescriptor, csBuilder)
createToFreshVariableSubstitutorAndAddInitialConstraints(candidateDescriptor, resolvedCall.atom, csBuilder)
val knownTypeParametersSubstitutor = knownTypeParametersResultingSubstitutor?.let {
createKnownParametersFromFreshVariablesSubstitutor(toFreshVariables, it)
@@ -220,6 +220,7 @@ internal object CreateFreshVariablesSubstitutor : ResolutionPart() {
fun createToFreshVariableSubstitutorAndAddInitialConstraints(
candidateDescriptor: CallableDescriptor,
kotlinCall: KotlinCall,
csBuilder: ConstraintSystemOperation
): FreshVariableNewTypeSubstitutor {
val typeParameters = candidateDescriptor.typeParameters
@@ -242,7 +243,7 @@ internal object CreateFreshVariablesSubstitutor : ResolutionPart() {
for (index in typeParameters.indices) {
val typeParameter = typeParameters[index]
val freshVariable = freshTypeVariables[index]
val position = DeclaredUpperBoundConstraintPositionImpl(typeParameter)
val position = DeclaredUpperBoundConstraintPositionImpl(typeParameter, kotlinCall)
for (upperBound in typeParameter.upperBounds) {
freshVariable.addSubtypeConstraint(upperBound, position)
@@ -263,7 +264,7 @@ internal object CreateFreshVariablesSubstitutor : ResolutionPart() {
// there can be null in case we already captured type parameter in outer class (in case of inner classes)
// see test innerClassTypeAliasConstructor.kt
val originalTypeParameter = originalTypeParameters.getOrNull(originalIndex) ?: continue
val position = DeclaredUpperBoundConstraintPositionImpl(originalTypeParameter)
val position = DeclaredUpperBoundConstraintPositionImpl(originalTypeParameter, kotlinCall)
for (upperBound in originalTypeParameter.upperBounds) {
freshVariable.addSubtypeConstraint(upperBound, position)
}
@@ -28,7 +28,8 @@ class BuilderInferenceSubstitutionConstraintPositionImpl(
class ExpectedTypeConstraintPositionImpl(topLevelCall: KotlinCall) : ExpectedTypeConstraintPosition<KotlinCall>(topLevelCall)
class DeclaredUpperBoundConstraintPositionImpl(
typeParameter: TypeParameterDescriptor
typeParameter: TypeParameterDescriptor,
val kotlinCall: KotlinCall
) : DeclaredUpperBoundConstraintPosition<TypeParameterDescriptor>(typeParameter) {
override fun toString() = "DeclaredUpperBound ${typeParameter.name} from ${typeParameter.containingDeclaration}"
}