Fix compiler exception during resolution of ambiguous callable references

Function return type can't and should not be used during overload resolution of callable references.
Since it can be DeferredType, its substitution in CS caused exception.
This commit is contained in:
Pavel Kirpichenkov
2019-10-17 18:33:38 +03:00
parent 8b97819c04
commit 138d558f6a
7 changed files with 78 additions and 3 deletions
@@ -112,7 +112,7 @@ class ReflectionTypes(module: ModuleDescriptor, private val notFoundClasses: Not
fun isNumberedKPropertyOrKMutablePropertyType(type: KotlinType): Boolean =
isNumberedKPropertyType(type) || isNumberedKMutablePropertyType(type)
private fun isKCallableType(type: KotlinType): Boolean =
fun isKCallableType(type: KotlinType): Boolean =
hasKCallableTypeFqName(type) || type.constructor.supertypes.any { isKCallableType(it) }
fun hasKCallableTypeFqName(type: KotlinType): Boolean =
@@ -21,6 +21,7 @@ import org.jetbrains.kotlin.types.typeUtil.asTypeProjection
import org.jetbrains.kotlin.types.typeUtil.replaceAnnotations
import org.jetbrains.kotlin.utils.DFS
import org.jetbrains.kotlin.utils.addIfNotNull
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
import java.util.*
private fun KotlinType.isTypeOrSubtypeOf(predicate: (KotlinType) -> Boolean): Boolean =
@@ -58,6 +59,9 @@ val KotlinType.isFunctionType: Boolean
val KotlinType.isSuspendFunctionType: Boolean
get() = constructor.declarationDescriptor?.getFunctionalClassKind() == FunctionClassDescriptor.Kind.SuspendFunction
val KotlinType.isCallableReflectionType: Boolean
get() = ReflectionTypes.isKCallableType(this)
val KotlinType.isKSuspendFunctionType: Boolean
get() = constructor.declarationDescriptor?.getFunctionalClassKind() == FunctionClassDescriptor.Kind.KSuspendFunction
@@ -139,6 +143,14 @@ fun KotlinType.getValueParameterTypesFromFunctionType(): List<TypeProjection> {
return arguments.subList(first, last)
}
fun KotlinType.getAllParameterProjectionsFromCallableReflectionType(): List<TypeProjection> {
assert(isCallableReflectionType) { "Not a callable reflection type: $this" }
val arguments = arguments
val last = arguments.size - 1
assert(last >= 0) { "Unexpected number of type arguments in type: $this" }
return arguments.subList(0, last)
}
fun KotlinType.extractParameterNameFromFunctionTypeArgument(): Name? {
val annotation = annotations.findAnnotation(KotlinBuiltIns.FQ_NAMES.parameterName) ?: return null
val name = (annotation.allValueArguments.values.singleOrNull() as? StringValue)