[NI] Add pre-resolution callable reference argument check.

If expected type for callable reference argument isn't callable type
then make such candidate unsuccessful.
Sometimes expected type is just `T`, where `T` is type variable.
To support such case we take all supertypes and check them instead.
This commit is contained in:
Stanislav Erokhin
2017-05-10 12:30:18 +03:00
committed by Mikhail Zarechenskiy
parent 55dc2c11f7
commit ee16a79612
5 changed files with 60 additions and 8 deletions
@@ -149,5 +149,26 @@ class ReflectionTypes(module: ModuleDescriptor, private val notFoundClasses: Not
return KotlinTypeFactory.simpleNotNullType(Annotations.EMPTY, kPropertyClass,
listOf(StarProjectionImpl(kPropertyClass.typeConstructor.parameters.single())))
}
fun isPossibleExpectedCallableType(typeConstructor: TypeConstructor): Boolean {
val descriptor = typeConstructor.declarationDescriptor as? ClassDescriptor ?: return false
if (KotlinBuiltIns.isAny(descriptor)) return true
val shortName = descriptor.name.asString()
val packageName = DescriptorUtils.getFqName(descriptor).parent().toSafe()
if (packageName == KOTLIN_REFLECT_FQ_NAME) {
return shortName.startsWith("KFunction") // KFunctionN, KFunction
|| shortName.startsWith("KProperty") // KPropertyN, KProperty
|| shortName.startsWith("KMutableProperty") // KMutablePropertyN, KMutableProperty
|| shortName == "KCallable" || shortName == "KAnnotatedElement"
}
if (packageName == KotlinBuiltIns.BUILT_INS_PACKAGE_FQ_NAME) {
return shortName.startsWith("Function") // FunctionN, Function
}
return false
}
}
}