Fir incorrect usage of AbstractExpectActualCompatibilityChecker.getCallablesCompatibility API

^KT-62027 Fixed

`getCallablesCompatibility` requires parentSubstitutor as a parameter,
but we created a member-level substitutor

`getCallablesCompatibility` will create member-level substitutor itself,
no need to create member-level substitutor on the call site.

IndexOutOfBounds was happening in an attempt of creating member-level
substitutor

I will refactor the `createExpectActualTypeParameterSubstitutor` API in
the following commits later. It will help to avoid problems like that
This commit is contained in:
Nikita Bobko
2023-09-19 12:18:42 +02:00
committed by Space Team
parent 9ff3871a8b
commit b15787bfa8
6 changed files with 50 additions and 6 deletions
@@ -137,6 +137,9 @@ private fun calculateExpectActualScopeDiff(
actual: ClassDescriptor,
): Set<ExpectActualMemberDiff<CallableMemberDescriptor, ClassDescriptor>> {
val matchingContext = ClassicExpectActualMatchingContext(actual.module)
// It's responsibility of AbstractExpectActualCompatibilityChecker to report that. Most probably this check is redundant,
// because we can't reach this line if expect and actual don't match, but let's have it for safety
if (expect.declaredTypeParameters.size != actual.declaredTypeParameters.size) return emptySet()
val classTypeSubstitutor = matchingContext.createExpectActualTypeParameterSubstitutor(
expect.declaredTypeParameters,
actual.declaredTypeParameters,
@@ -156,15 +159,10 @@ private fun calculateExpectActualScopeDiff(
} else {
potentialExpects
.map { expectMember ->
val substitutor = matchingContext.createExpectActualTypeParameterSubstitutor(
expectMember.typeParameters,
actualMember.typeParameters,
classTypeSubstitutor
)
AbstractExpectActualCompatibilityChecker.getCallablesCompatibility(
expectMember,
actualMember,
substitutor,
classTypeSubstitutor,
expect,
actual,
matchingContext