Supported obtaining function type parameter names from KotlinType
This commit is contained in:
@@ -213,7 +213,10 @@ class TypeResolver(
|
||||
else moduleDescriptor.builtIns.unitType
|
||||
|
||||
result = type(createFunctionType(
|
||||
moduleDescriptor.builtIns, annotations, receiverType, parameterDescriptors.map { it.type }, returnType
|
||||
moduleDescriptor.builtIns, annotations, receiverType,
|
||||
parameterDescriptors.map { it.type },
|
||||
parameterDescriptors.map { it.name },
|
||||
returnType
|
||||
))
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,8 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||
import org.jetbrains.kotlin.builtins.ReflectionTypes;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
|
||||
import org.jetbrains.kotlin.diagnostics.Errors;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.name.SpecialNames;
|
||||
import org.jetbrains.kotlin.psi.*;
|
||||
import org.jetbrains.kotlin.resolve.BindingTrace;
|
||||
import org.jetbrains.kotlin.resolve.TemporaryBindingTrace;
|
||||
@@ -270,7 +272,7 @@ public class ArgumentTypeResolver {
|
||||
}
|
||||
|
||||
return FunctionTypeResolveUtilsKt.createFunctionType(
|
||||
builtIns, Annotations.Companion.getEMPTY(), null, Collections.<KotlinType>emptyList(), TypeUtils.DONT_CARE
|
||||
builtIns, Annotations.Companion.getEMPTY(), null, Collections.<KotlinType>emptyList(), Collections.<Name>emptyList(), TypeUtils.DONT_CARE
|
||||
);
|
||||
}
|
||||
|
||||
@@ -301,15 +303,21 @@ public class ArgumentTypeResolver {
|
||||
? functionPlaceholders
|
||||
.createFunctionPlaceholderType(Collections.<KotlinType>emptyList(), /* hasDeclaredArguments = */ false)
|
||||
: FunctionTypeResolveUtilsKt.createFunctionType(
|
||||
builtIns, Annotations.Companion.getEMPTY(), null, Collections.<KotlinType>emptyList(), DONT_CARE
|
||||
builtIns, Annotations.Companion.getEMPTY(), null, Collections.<KotlinType>emptyList(), Collections.<Name>emptyList(), DONT_CARE
|
||||
);
|
||||
}
|
||||
List<KtParameter> valueParameters = function.getValueParameters();
|
||||
TemporaryBindingTrace temporaryTrace = TemporaryBindingTrace.create(
|
||||
trace, "trace to resolve function literal parameter types");
|
||||
List<KotlinType> parameterTypes = Lists.newArrayList();
|
||||
List<Name> parameterNames = Lists.newArrayList();
|
||||
for (KtParameter parameter : valueParameters) {
|
||||
parameterTypes.add(resolveTypeRefWithDefault(parameter.getTypeReference(), scope, temporaryTrace, DONT_CARE));
|
||||
Name name = parameter.getNameAsName();
|
||||
if (name == null) {
|
||||
name = SpecialNames.NO_NAME_PROVIDED;
|
||||
}
|
||||
parameterNames.add(name);
|
||||
}
|
||||
KotlinType returnType = resolveTypeRefWithDefault(function.getTypeReference(), scope, temporaryTrace, DONT_CARE);
|
||||
assert returnType != null;
|
||||
@@ -318,7 +326,7 @@ public class ArgumentTypeResolver {
|
||||
return expectedTypeIsUnknown && isFunctionLiteral
|
||||
? functionPlaceholders.createFunctionPlaceholderType(parameterTypes, /* hasDeclaredArguments = */ true)
|
||||
: FunctionTypeResolveUtilsKt.createFunctionType(
|
||||
builtIns, Annotations.Companion.getEMPTY(), receiverType, parameterTypes, returnType
|
||||
builtIns, Annotations.Companion.getEMPTY(), receiverType, parameterTypes, parameterNames, returnType
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.config.LanguageVersionSettings;
|
||||
import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.name.SpecialNames;
|
||||
import org.jetbrains.kotlin.progress.ProgressIndicatorAndCompilationCanceledStatus;
|
||||
import org.jetbrains.kotlin.psi.*;
|
||||
import org.jetbrains.kotlin.resolve.*;
|
||||
@@ -290,11 +291,13 @@ public class CallResolver {
|
||||
if (calleeExpression instanceof KtLambdaExpression) {
|
||||
int parameterNumber = ((KtLambdaExpression) calleeExpression).getValueParameters().size();
|
||||
List<KotlinType> parameterTypes = new ArrayList<KotlinType>(parameterNumber);
|
||||
List<Name> parameterNames = new ArrayList<Name>(parameterNumber);
|
||||
for (int i = 0; i < parameterNumber; i++) {
|
||||
parameterTypes.add(NO_EXPECTED_TYPE);
|
||||
parameterNames.add(SpecialNames.NO_NAME_PROVIDED);
|
||||
}
|
||||
expectedType = FunctionTypeResolveUtilsKt.createFunctionType(
|
||||
builtIns, Annotations.Companion.getEMPTY(), null, parameterTypes, context.expectedType
|
||||
builtIns, Annotations.Companion.getEMPTY(), null, parameterTypes, parameterNames, context.expectedType
|
||||
);
|
||||
}
|
||||
KotlinType calleeType = expressionTypingServices.safeGetType(
|
||||
|
||||
+5
-1
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.resolve.calls.inference
|
||||
import org.jetbrains.kotlin.builtins.isExtensionFunctionType
|
||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.name.SpecialNames
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilderImpl.ConstraintKind.EQUAL
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilderImpl.ConstraintKind.SUB_TYPE
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.TypeBounds.Bound
|
||||
@@ -37,6 +38,8 @@ import org.jetbrains.kotlin.types.checker.TypeCheckingProcedureCallbacks
|
||||
import org.jetbrains.kotlin.types.typeUtil.builtIns
|
||||
import org.jetbrains.kotlin.types.typeUtil.defaultProjections
|
||||
import org.jetbrains.kotlin.types.typeUtil.isDefaultBound
|
||||
import java.lang.IllegalArgumentException
|
||||
import java.lang.IllegalStateException
|
||||
import java.util.*
|
||||
|
||||
open class ConstraintSystemBuilderImpl(private val mode: Mode = ConstraintSystemBuilderImpl.Mode.INFERENCE) : ConstraintSystem.Builder {
|
||||
@@ -446,5 +449,6 @@ internal fun createTypeForFunctionPlaceholder(
|
||||
functionPlaceholderTypeConstructor.argumentTypes
|
||||
}
|
||||
val receiverType = if (isExtension) DONT_CARE else null
|
||||
return createFunctionType(functionPlaceholder.builtIns, Annotations.EMPTY, receiverType, newArgumentTypes, DONT_CARE)
|
||||
val parameterNames = newArgumentTypes.map { SpecialNames.NO_NAME_PROVIDED }
|
||||
return createFunctionType(functionPlaceholder.builtIns, Annotations.EMPTY, receiverType, newArgumentTypes, parameterNames, DONT_CARE)
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.descriptors.impl.*
|
||||
import org.jetbrains.kotlin.incremental.components.LookupLocation
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.name.SpecialNames
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.resolve.DescriptorFactory
|
||||
import org.jetbrains.kotlin.resolve.calls.util.createFunctionType
|
||||
@@ -175,8 +176,9 @@ class DynamicCallableDescriptors(builtIns: KotlinBuiltIns) {
|
||||
|
||||
val receiverType = funLiteral.receiverTypeReference?.let { dynamicType }
|
||||
val parameterTypes = funLiteral.valueParameters.map { dynamicType }
|
||||
val parameterNames = funLiteral.valueParameters.map { it.nameAsName ?: SpecialNames.NO_NAME_PROVIDED }
|
||||
|
||||
return createFunctionType(owner.builtIns, Annotations.EMPTY, receiverType, parameterTypes, dynamicType)
|
||||
return createFunctionType(owner.builtIns, Annotations.EMPTY, receiverType, parameterTypes, parameterNames, dynamicType)
|
||||
}
|
||||
|
||||
for (arg in call.valueArguments) {
|
||||
|
||||
@@ -132,6 +132,7 @@ internal class FunctionsTypingVisitor(facade: ExpressionTypingInternals) : Expre
|
||||
Annotations.EMPTY,
|
||||
extensionReceiverParameter?.type,
|
||||
valueParameters.map { it.type },
|
||||
valueParameters.map { it.name },
|
||||
returnType ?: return null
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user