VarianceChecker: correct handing of nested classes and their methods #KT-14733 Fixed
This commit is contained in:
@@ -66,13 +66,19 @@ class VarianceCheckerCore(
|
||||
if (!checkClassHeader(klass)) return false
|
||||
}
|
||||
for (member in klass.declarations + klass.getPrimaryConstructorParameters()) {
|
||||
member as? KtCallableDeclaration ?: continue
|
||||
val descriptor = when (member) {
|
||||
is KtParameter -> context.get(BindingContext.PRIMARY_CONSTRUCTOR_PARAMETER, member)
|
||||
is KtCallableDeclaration -> context.get(BindingContext.DECLARATION_TO_DESCRIPTOR, member)
|
||||
is KtDeclaration -> context.get(BindingContext.DECLARATION_TO_DESCRIPTOR, member)
|
||||
else -> null
|
||||
} as? CallableMemberDescriptor ?: continue
|
||||
if (!checkMember(member, descriptor)) return false
|
||||
} as? MemberDescriptor ?: continue
|
||||
when (member) {
|
||||
is KtClassOrObject -> {
|
||||
if (!checkClassOrObject(member)) return false
|
||||
}
|
||||
is KtCallableDeclaration -> {
|
||||
if (descriptor is CallableMemberDescriptor && !checkMember(member, descriptor)) return false
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
@@ -103,7 +109,7 @@ class VarianceCheckerCore(
|
||||
Visibilities.isPrivate(descriptor.visibility) || checkCallableDeclaration(context, member, descriptor)
|
||||
|
||||
private fun TypeParameterDescriptor.varianceWithManual() =
|
||||
if (manualVariance != null && this == manualVariance.descriptor) manualVariance.variance else variance
|
||||
if (manualVariance != null && this.original == manualVariance.descriptor) manualVariance.variance else variance
|
||||
|
||||
fun recordPrivateToThisIfNeeded(descriptor: CallableMemberDescriptor) {
|
||||
if (isIrrelevant(descriptor) || descriptor.visibility != Visibilities.PRIVATE) return
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
|
||||
abstract class TestOut<T> {
|
||||
abstract fun test(): T
|
||||
|
||||
abstract inner class InnerTest {
|
||||
abstract fun innerTest(test: T)
|
||||
}
|
||||
}
|
||||
|
||||
abstract class TestIn<T> {
|
||||
abstract fun test(test: T)
|
||||
|
||||
abstract inner class InnerTest {
|
||||
abstract fun innerTest(): T
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user