EA-71185 - assert: CallResolverUtilPackage$CallResolverUtil$fcfb.hasUnknownReturnType
- Accept any subclasses of KCallable<R> as "callable reflection types" (this includes KProperty and KFunction with their subclasses). - Provide more detailed information on the callable reference type in question in case of assertion failures.
This commit is contained in:
@@ -44,19 +44,19 @@ public enum class ResolveArgumentsMode {
|
|||||||
|
|
||||||
|
|
||||||
public fun hasUnknownFunctionParameter(type: JetType): Boolean {
|
public fun hasUnknownFunctionParameter(type: JetType): Boolean {
|
||||||
assert(ReflectionTypes.isCallableType(type), "type is not a function or property")
|
assert(ReflectionTypes.isCallableType(type)) { "type $type is not a function or property" }
|
||||||
return getParameterArgumentsOfCallableType(type).any {
|
return getParameterArgumentsOfCallableType(type).any {
|
||||||
TypeUtils.containsSpecialType(it.getType(), DONT_CARE) || ErrorUtils.containsUninferredParameter(it.getType())
|
TypeUtils.containsSpecialType(it.getType(), DONT_CARE) || ErrorUtils.containsUninferredParameter(it.getType())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun hasUnknownReturnType(type: JetType): Boolean {
|
public fun hasUnknownReturnType(type: JetType): Boolean {
|
||||||
assert(ReflectionTypes.isCallableType(type), "type is not a function or property")
|
assert(ReflectionTypes.isCallableType(type)) { "type $type is not a function or property" }
|
||||||
return ErrorUtils.containsErrorType(getReturnTypeForCallable(type))
|
return ErrorUtils.containsErrorType(getReturnTypeForCallable(type))
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun replaceReturnTypeByUnknown(type: JetType): JetType {
|
public fun replaceReturnTypeByUnknown(type: JetType): JetType {
|
||||||
assert(ReflectionTypes.isCallableType(type), "type is not a function or property")
|
assert(ReflectionTypes.isCallableType(type)) { "type $type is not a function or property" }
|
||||||
val newArguments = Lists.newArrayList<TypeProjection>()
|
val newArguments = Lists.newArrayList<TypeProjection>()
|
||||||
newArguments.addAll(getParameterArgumentsOfCallableType(type))
|
newArguments.addAll(getParameterArgumentsOfCallableType(type))
|
||||||
newArguments.add(TypeProjectionImpl(Variance.INVARIANT, DONT_CARE))
|
newArguments.add(TypeProjectionImpl(Variance.INVARIANT, DONT_CARE))
|
||||||
|
|||||||
@@ -114,22 +114,17 @@ public class ReflectionTypes(private val module: ModuleDescriptor) {
|
|||||||
return containingPackage != null && containingPackage.fqName == KOTLIN_REFLECT_FQ_NAME
|
return containingPackage != null && containingPackage.fqName == KOTLIN_REFLECT_FQ_NAME
|
||||||
}
|
}
|
||||||
|
|
||||||
private val PROPERTY_CLASS_NAMES = hashSetOf(
|
private val KCALLABLE_CLASS_NAME = "KCallable"
|
||||||
"KProperty", "KMutableProperty",
|
|
||||||
"KProperty0", "KMutableProperty0",
|
|
||||||
"KProperty1", "KMutableProperty1",
|
|
||||||
"KProperty2", "KMutableProperty2"
|
|
||||||
)
|
|
||||||
|
|
||||||
public fun isCallableType(type: JetType): Boolean =
|
public fun isCallableType(type: JetType): Boolean =
|
||||||
KotlinBuiltIns.isFunctionOrExtensionFunctionType(type) ||
|
KotlinBuiltIns.isFunctionOrExtensionFunctionType(type) ||
|
||||||
isPropertyType(type)
|
isCallableReflectionType(type)
|
||||||
|
|
||||||
public fun isPropertyType(type: JetType): Boolean =
|
public fun isCallableReflectionType(type: JetType): Boolean =
|
||||||
isExactPropertyType(type) ||
|
isExactCallableReflectionType(type) ||
|
||||||
type.getConstructor().getSupertypes().any { isPropertyType(it) }
|
type.constructor.getSupertypes().any { isCallableReflectionType(it) }
|
||||||
|
|
||||||
public fun isExactPropertyType(type: JetType): Boolean {
|
public fun isExactCallableReflectionType(type: JetType): Boolean {
|
||||||
val descriptor = type.getConstructor().getDeclarationDescriptor()
|
val descriptor = type.getConstructor().getDeclarationDescriptor()
|
||||||
if (descriptor is ClassDescriptor) {
|
if (descriptor is ClassDescriptor) {
|
||||||
val fqName = DescriptorUtils.getFqName(descriptor)
|
val fqName = DescriptorUtils.getFqName(descriptor)
|
||||||
@@ -137,7 +132,7 @@ public class ReflectionTypes(private val module: ModuleDescriptor) {
|
|||||||
if (parentName != KOTLIN_REFLECT_FQ_NAME.asString())
|
if (parentName != KOTLIN_REFLECT_FQ_NAME.asString())
|
||||||
return false
|
return false
|
||||||
val shortName = fqName.shortName().asString()
|
val shortName = fqName.shortName().asString()
|
||||||
return PROPERTY_CLASS_NAMES.contains(shortName)
|
return KCALLABLE_CLASS_NAME == shortName
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user