Type-check reference to property with invisible setter to KProperty

#KT-12337 Fixed
This commit is contained in:
Alexander Udalov
2016-06-15 17:53:52 +03:00
parent c5a208f3eb
commit 6562a2db19
13 changed files with 145 additions and 19 deletions
@@ -216,6 +216,9 @@ public abstract class KotlinBuiltIns {
public final FqNameUnsafe kClass = reflect("KClass");
public final FqNameUnsafe kCallable = reflect("KCallable");
public final FqNameUnsafe kMutableProperty0 = reflect("KMutableProperty0");
public final FqNameUnsafe kMutableProperty1 = reflect("KMutableProperty1");
public final FqNameUnsafe kMutableProperty2 = reflect("KMutableProperty2");
public final ClassId kProperty = ClassId.topLevel(reflect("KProperty").toSafe());
public final Map<FqNameUnsafe, PrimitiveType> fqNameToPrimitiveType;
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.FqNameUnsafe
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.scopes.MemberScope
@@ -120,12 +121,19 @@ class ReflectionTypes(module: ModuleDescriptor) {
type.isFunctionTypeOrSubtype || isKCallableType(type)
private fun isKCallableType(type: KotlinType): Boolean =
isExactKCallableType(type) ||
hasFqName(type.constructor, KotlinBuiltIns.FQ_NAMES.kCallable) ||
type.constructor.supertypes.any { isKCallableType(it) }
private fun isExactKCallableType(type: KotlinType): Boolean {
val descriptor = type.constructor.declarationDescriptor
return descriptor is ClassDescriptor && DescriptorUtils.getFqName(descriptor) == KotlinBuiltIns.FQ_NAMES.kCallable
fun isKMutablePropertyType(type: KotlinType): Boolean {
val typeConstructor = type.constructor
return hasFqName(typeConstructor, KotlinBuiltIns.FQ_NAMES.kMutableProperty0) ||
hasFqName(typeConstructor, KotlinBuiltIns.FQ_NAMES.kMutableProperty1) ||
hasFqName(typeConstructor, KotlinBuiltIns.FQ_NAMES.kMutableProperty2)
}
private fun hasFqName(typeConstructor: TypeConstructor, fqName: FqNameUnsafe): Boolean {
val descriptor = typeConstructor.declarationDescriptor as? ClassDescriptor ?: return false
return descriptor.name == fqName.shortName() && DescriptorUtils.getFqName(descriptor) == fqName
}
fun createKPropertyStarType(module: ModuleDescriptor): KotlinType? {