Distinguish between no declared arguments and an empty argument list
in a function literal If there are no arguments, any number of them might be expected
This commit is contained in:
committed by
Alexander Udalov
parent
d9568ef88c
commit
14c2690447
+2
-3
@@ -423,10 +423,9 @@ fun createCorrespondingFunctionTypeForFunctionPlaceholder(
|
||||
): JetType {
|
||||
assert(ErrorUtils.isFunctionPlaceholder(functionPlaceholder)) { "Function placeholder type expected: $functionPlaceholder" }
|
||||
val functionPlaceholderTypeConstructor = functionPlaceholder.getConstructor() as FunctionPlaceholderTypeConstructor
|
||||
val declaredArgumentTypes = functionPlaceholderTypeConstructor.getArgumentTypes()
|
||||
|
||||
val isExtension = KotlinBuiltIns.isExtensionFunctionType(expectedType)
|
||||
val newArgumentTypes = if (declaredArgumentTypes.isEmpty()) {
|
||||
val newArgumentTypes = if (!functionPlaceholderTypeConstructor.hasDeclaredArguments()) {
|
||||
val typeParamSize = expectedType.getConstructor().getParameters().size()
|
||||
// the first parameter is receiver (if present), the last one is return type,
|
||||
// the remaining are function arguments
|
||||
@@ -436,7 +435,7 @@ fun createCorrespondingFunctionTypeForFunctionPlaceholder(
|
||||
result
|
||||
}
|
||||
else {
|
||||
declaredArgumentTypes
|
||||
functionPlaceholderTypeConstructor.getArgumentTypes()
|
||||
}
|
||||
val receiverType = if (isExtension) DONT_CARE else null
|
||||
return KotlinBuiltIns.getInstance().getFunctionType(Annotations.EMPTY, receiverType, newArgumentTypes, DONT_CARE)
|
||||
|
||||
@@ -546,19 +546,21 @@ public class ErrorUtils {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetType createFunctionPlaceholderType(@NotNull List<JetType> argumentTypes) {
|
||||
public static JetType createFunctionPlaceholderType(@NotNull List<JetType> argumentTypes, boolean hasDeclaredArguments) {
|
||||
return new ErrorTypeImpl(
|
||||
new FunctionPlaceholderTypeConstructor(argumentTypes),
|
||||
new FunctionPlaceholderTypeConstructor(argumentTypes, hasDeclaredArguments),
|
||||
createErrorScope("Scope for function placeholder type"));
|
||||
}
|
||||
|
||||
public static class FunctionPlaceholderTypeConstructor implements TypeConstructor {
|
||||
private final TypeConstructor errorTypeConstructor;
|
||||
private final List<JetType> argumentTypes;
|
||||
private final boolean hasDeclaredArguments;
|
||||
|
||||
private FunctionPlaceholderTypeConstructor(@NotNull List<JetType> argumentTypes) {
|
||||
private FunctionPlaceholderTypeConstructor(@NotNull List<JetType> argumentTypes, boolean hasDeclaredArguments) {
|
||||
errorTypeConstructor = createErrorTypeConstructorWithCustomDebugName("PLACEHOLDER_FUNCTION_TYPE" + argumentTypes);
|
||||
this.argumentTypes = argumentTypes;
|
||||
this.hasDeclaredArguments = hasDeclaredArguments;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -566,6 +568,10 @@ public class ErrorUtils {
|
||||
return argumentTypes;
|
||||
}
|
||||
|
||||
public boolean hasDeclaredArguments() {
|
||||
return hasDeclaredArguments;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<TypeParameterDescriptor> getParameters() {
|
||||
|
||||
Reference in New Issue
Block a user