ParameterName annotation on type argument used to hold parameter name

This commit is contained in:
Valentin Kipyatkov
2016-09-14 19:37:44 +03:00
parent 3bd39df587
commit 59269ef1ae
37 changed files with 158 additions and 140 deletions
@@ -16,7 +16,10 @@
package org.jetbrains.kotlin.resolve
import org.jetbrains.kotlin.builtins.*
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.builtins.getReceiverTypeFromFunctionType
import org.jetbrains.kotlin.builtins.getValueParameterTypesFromFunctionType
import org.jetbrains.kotlin.builtins.isFunctionType
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.descriptors.impl.ClassConstructorDescriptorImpl
@@ -48,7 +51,6 @@ import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.TypeUtils
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
import org.jetbrains.kotlin.types.expressions.ExpressionTypingServices
import org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils
import org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils.isFunctionExpression
import org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils.isFunctionLiteral
import java.util.*
@@ -208,7 +210,7 @@ class FunctionDescriptorResolver(
return listOf(it)
}
if (function.valueParameters.size != expectedValueParameters.size) {
val expectedParameterTypes = ExpressionTypingUtils.getValueParametersTypes(expectedValueParameters)
val expectedParameterTypes = expectedValueParameters.map { it.type }
trace.report(EXPECTED_PARAMETERS_NUMBER_MISMATCH.on(function, expectedParameterTypes.size, expectedParameterTypes))
}
}
@@ -226,11 +228,11 @@ class FunctionDescriptorResolver(
private fun KotlinType.functionTypeExpected() = !TypeUtils.noExpectedType(this) && isFunctionType
private fun KotlinType.getReceiverType(): KotlinType? =
if (functionTypeExpected()) getReceiverTypeFromFunctionType(this) else null
if (functionTypeExpected()) this.getReceiverTypeFromFunctionType() else null
private fun KotlinType.getValueParameters(owner: FunctionDescriptor): List<ValueParameterDescriptor>? =
if (functionTypeExpected()) {
createValueParametersForInvokeInFunctionType(owner, getValueParameterTypesFromFunctionType(this))
createValueParametersForInvokeInFunctionType(owner, this.getValueParameterTypesFromFunctionType())
}
else null
@@ -181,7 +181,7 @@ class CallCompleter(
if (call.isCallableReference()) {
// TODO: compute generic type argument for R in the kotlin.Function<R> supertype (KT-12963)
// TODO: also add constraints for parameter types (KT-12964)
if (!TypeUtils.noExpectedType(expectedType) && expectedType.isFunctionType) getReturnTypeFromFunctionType(expectedType)
if (!TypeUtils.noExpectedType(expectedType) && expectedType.isFunctionType) expectedType.getReturnTypeFromFunctionType()
else TypeUtils.NO_EXPECTED_TYPE
}
else expectedType
@@ -174,7 +174,7 @@ fun getEffectiveExpectedType(parameterDescriptor: ValueParameterDescriptor, argu
argument.getArgumentExpression() is KtLambdaExpression &&
parameterDescriptor.type.isExtensionFunctionType
) {
val receiverType = getReceiverTypeFromFunctionType(parameterDescriptor.type)!!
val receiverType = parameterDescriptor.type.getReceiverTypeFromFunctionType()!!
val newExpectedLambdaReturnType =
receiverType.memberScope
@@ -56,7 +56,7 @@ object CoroutineModifierChecker : SimpleDeclarationChecker {
continue
}
val returnType = getReturnTypeFromFunctionType(parameterDescriptor.type)
val returnType = parameterDescriptor.type.getReturnTypeFromFunctionType()
if (returnType.isMarkedNullable || !returnType.isValidContinuation() || !returnType.arguments.single().type.isUnit()) {
report("parameter should have function type like 'Controller.() -> Continuation<Unit>' (Continuation<Unit> for return type is necessary)")
@@ -68,7 +68,7 @@ object CoroutineModifierChecker : SimpleDeclarationChecker {
continue
}
val controller = getReceiverTypeFromFunctionType(parameterDescriptor.type)!!
val controller = parameterDescriptor.type.getReceiverTypeFromFunctionType()!!
val handleResultFunctions =
controller.memberScope
@@ -40,6 +40,7 @@ import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
import org.jetbrains.kotlin.resolve.calls.util.CallMaker
import org.jetbrains.kotlin.resolve.calls.util.FakeCallableDescriptorForObject
import org.jetbrains.kotlin.resolve.calls.util.createValueParametersForInvokeInFunctionType
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
import org.jetbrains.kotlin.resolve.scopes.receivers.ClassQualifier
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
import org.jetbrains.kotlin.resolve.scopes.receivers.Receiver
@@ -48,6 +49,7 @@ import org.jetbrains.kotlin.resolve.source.toSourceElement
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.types.TypeUtils.NO_EXPECTED_TYPE
import org.jetbrains.kotlin.types.expressions.typeInfoFactory.createTypeInfo
import java.lang.UnsupportedOperationException
import javax.inject.Inject
sealed class DoubleColonLHS(val type: KotlinType) {
@@ -534,8 +536,10 @@ class DoubleColonExpressionResolver(
return when (descriptor) {
is FunctionDescriptor -> {
val returnType = descriptor.returnType ?: return null
val valueParametersTypes = ExpressionTypingUtils.getValueParametersTypes(descriptor.valueParameters)
return reflectionTypes.getKFunctionType(Annotations.EMPTY, receiverType, valueParametersTypes, returnType)
val parametersTypes = descriptor.valueParameters.map { it.type }
val parametersNames = descriptor.valueParameters.map { it.name }
return reflectionTypes.getKFunctionType(Annotations.EMPTY, receiverType,
parametersTypes, parametersNames, returnType, descriptor.builtIns)
}
is PropertyDescriptor -> {
val mutable = descriptor.isVar && run {
@@ -187,7 +187,7 @@ internal class FunctionsTypingVisitor(facade: ExpressionTypingInternals) : Expre
functionDescriptor: SimpleFunctionDescriptorImpl,
functionTypeExpected: Boolean
): KotlinType {
val expectedReturnType = if (functionTypeExpected) getReturnTypeFromFunctionType(context.expectedType) else null
val expectedReturnType = if (functionTypeExpected) context.expectedType.getReturnTypeFromFunctionType() else null
val returnType = computeUnsafeReturnType(expression, context, functionDescriptor, expectedReturnType)
if (!expression.functionLiteral.hasDeclaredReturnType() && functionTypeExpected) {