Add variance modifier fix corrected: primary constructor parameters are taken into account

This commit is contained in:
Mikhail Glukhikh
2016-04-15 16:02:41 +03:00
parent 027cc898e7
commit e60930d5ce
2 changed files with 11 additions and 3 deletions
@@ -71,9 +71,13 @@ class VarianceCheckerCore(
if (klass is KtClass) {
if (!checkClassHeader(klass)) return false
}
for (member in klass.declarations) {
for (member in klass.declarations + klass.getPrimaryConstructorParameters()) {
member as? KtCallableDeclaration ?: continue
val descriptor = context.get(BindingContext.DECLARATION_TO_DESCRIPTOR, member) as? CallableMemberDescriptor ?: continue
val descriptor = when (member) {
is KtParameter -> context.get(BindingContext.PRIMARY_CONSTRUCTOR_PARAMETER, member)
is KtCallableDeclaration -> context.get(BindingContext.DECLARATION_TO_DESCRIPTOR, member)
else -> null
} as? CallableMemberDescriptor ?: continue
if (!checkMember(member, descriptor)) return false
}
return true
+5 -1
View File
@@ -21,4 +21,8 @@ abstract class AbstractOut<T> {
abstract class AbstractIn<T>(private val foo: T) {
fun bar(arg: T) = foo == arg
}
interface Empty<T>
interface Empty<T>
abstract class AbstractInv<T>(var foo: T)
class InvUser<T>(val user: AbstractInv<T>)