Do not take ParameterName annotations into implicit lambda signature

This commit is contained in:
Valentin Kipyatkov
2016-10-07 19:33:07 +03:00
parent 03320d6559
commit 5e32589084
@@ -22,6 +22,7 @@ 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.annotations.AnnotationsImpl
import org.jetbrains.kotlin.descriptors.impl.ClassConstructorDescriptorImpl
import org.jetbrains.kotlin.descriptors.impl.FunctionExpressionDescriptor
import org.jetbrains.kotlin.descriptors.impl.SimpleFunctionDescriptorImpl
@@ -53,6 +54,7 @@ import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
import org.jetbrains.kotlin.types.expressions.ExpressionTypingServices
import org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils.isFunctionExpression
import org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils.isFunctionLiteral
import org.jetbrains.kotlin.types.typeUtil.replaceAnnotations
import java.util.*
class FunctionDescriptorResolver(
@@ -197,12 +199,13 @@ class FunctionDescriptorResolver(
expectedFunctionType: KotlinType
): List<ValueParameterDescriptor> {
val expectedValueParameters = expectedFunctionType.getValueParameters(functionDescriptor)
val expectedParameterTypes = expectedValueParameters?.map { it.type.removeParameterNameAnnotation() }
if (expectedValueParameters != null) {
if (expectedValueParameters.size == 1 && function is KtFunctionLiteral && function.getValueParameterList() == null) {
// it parameter for lambda
val valueParameterDescriptor = expectedValueParameters.first()
val valueParameterDescriptor = expectedValueParameters.single()
val it = ValueParameterDescriptorImpl(functionDescriptor, null, 0, Annotations.EMPTY, Name.identifier("it"),
valueParameterDescriptor.type, valueParameterDescriptor.declaresDefaultValue(),
expectedParameterTypes!!.single(), valueParameterDescriptor.declaresDefaultValue(),
valueParameterDescriptor.isCrossinline, valueParameterDescriptor.isNoinline,
valueParameterDescriptor.isCoroutine,
valueParameterDescriptor.varargElementType, SourceElement.NO_SOURCE)
@@ -210,8 +213,7 @@ class FunctionDescriptorResolver(
return listOf(it)
}
if (function.valueParameters.size != expectedValueParameters.size) {
val expectedParameterTypes = expectedValueParameters.map { it.type }
trace.report(EXPECTED_PARAMETERS_NUMBER_MISMATCH.on(function, expectedParameterTypes.size, expectedParameterTypes))
trace.report(EXPECTED_PARAMETERS_NUMBER_MISMATCH.on(function, expectedParameterTypes!!.size, expectedParameterTypes))
}
}
@@ -222,10 +224,16 @@ class FunctionDescriptorResolver(
innerScope,
function.valueParameters,
trace,
expectedValueParameters
expectedParameterTypes
)
}
private fun KotlinType.removeParameterNameAnnotation(): KotlinType {
if (this is TypeUtils.SpecialType) return this
val parameterNameAnnotation = annotations.findAnnotation(KotlinBuiltIns.FQ_NAMES.parameterName) ?: return this
return replaceAnnotations(AnnotationsImpl(annotations.filter { it != parameterNameAnnotation }))
}
private fun KotlinType.functionTypeExpected() = !TypeUtils.noExpectedType(this) && isFunctionType
private fun KotlinType.getReceiverType(): KotlinType? =
if (functionTypeExpected()) this.getReceiverTypeFromFunctionType() else null
@@ -312,14 +320,14 @@ class FunctionDescriptorResolver(
parameterScope: LexicalWritableScope,
valueParameters: List<KtParameter>,
trace: BindingTrace,
expectedValueParameters: List<ValueParameterDescriptor>?
expectedParameterTypes: List<KotlinType>?
): List<ValueParameterDescriptor> {
val result = ArrayList<ValueParameterDescriptor>()
for (i in valueParameters.indices) {
val valueParameter = valueParameters[i]
val typeReference = valueParameter.typeReference
val expectedType = expectedValueParameters?.let { if (i < it.size) it[i].type else null }
val expectedType = expectedParameterTypes?.let { if (i < it.size) it[i] else null }
val type: KotlinType
if (typeReference != null) {