Simplify and rename function type utilities
- isFunctionType -> change the only usage in TracingStrategyForInvoke to check for exact function type - isExtensionFunctionType -> change all usages to check for exact extension function type because extension function types are uninheritable in Kotlin - isExactFunctionType -> isNonExtensionFunctionType - isExactExtensionFunctionType -> isExtensionFunctionType - isExactFunctionOrExtensionFunctionType -> isFunctionType - isFunctionOrExtensionFunctionType -> isFunctionTypeOrSubtype
This commit is contained in:
@@ -444,7 +444,7 @@ public class BodyResolver {
|
||||
if (classDescriptor != null) {
|
||||
if (ErrorUtils.isError(classDescriptor)) continue;
|
||||
|
||||
if (FunctionTypesKt.isExactExtensionFunctionType(supertype)) {
|
||||
if (FunctionTypesKt.isExtensionFunctionType(supertype)) {
|
||||
trace.report(SUPERTYPE_IS_EXTENSION_FUNCTION_TYPE.on(typeReference));
|
||||
}
|
||||
|
||||
|
||||
@@ -612,7 +612,7 @@ public class DescriptorResolver {
|
||||
if (DynamicTypesKt.isDynamic(upperBoundType)) {
|
||||
trace.report(DYNAMIC_UPPER_BOUND.on(upperBound));
|
||||
}
|
||||
if (FunctionTypesKt.isExactExtensionFunctionType(upperBoundType)) {
|
||||
if (FunctionTypesKt.isExtensionFunctionType(upperBoundType)) {
|
||||
trace.report(UPPER_BOUND_IS_EXTENSION_FUNCTION_TYPE.on(upperBound));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ package org.jetbrains.kotlin.resolve
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.builtins.getReceiverTypeFromFunctionType
|
||||
import org.jetbrains.kotlin.builtins.getValueParametersFromFunctionType
|
||||
import org.jetbrains.kotlin.builtins.isFunctionOrExtensionFunctionType
|
||||
import org.jetbrains.kotlin.builtins.isFunctionTypeOrSubtype
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.descriptors.impl.ConstructorDescriptorImpl
|
||||
@@ -220,7 +220,7 @@ class FunctionDescriptorResolver(
|
||||
)
|
||||
}
|
||||
|
||||
private fun KotlinType.functionTypeExpected() = !TypeUtils.noExpectedType(this) && isFunctionOrExtensionFunctionType
|
||||
private fun KotlinType.functionTypeExpected() = !TypeUtils.noExpectedType(this) && isFunctionTypeOrSubtype
|
||||
private fun KotlinType.getReceiverType(): KotlinType? =
|
||||
if (functionTypeExpected()) getReceiverTypeFromFunctionType(this) else null
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.resolve
|
||||
|
||||
import org.jetbrains.kotlin.builtins.isFunctionOrExtensionFunctionType
|
||||
import org.jetbrains.kotlin.builtins.isFunctionTypeOrSubtype
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticSink
|
||||
import org.jetbrains.kotlin.diagnostics.Errors
|
||||
@@ -34,7 +34,7 @@ object InlineParameterChecker : DeclarationChecker {
|
||||
val inline = declaration.hasModifier(KtTokens.INLINE_KEYWORD)
|
||||
for (parameter in declaration.valueParameters) {
|
||||
val parameterDescriptor = bindingContext.get(BindingContext.VALUE_PARAMETER, parameter)
|
||||
if (!inline || (parameterDescriptor != null && !parameterDescriptor.type.isFunctionOrExtensionFunctionType)) {
|
||||
if (!inline || (parameterDescriptor != null && !parameterDescriptor.type.isFunctionTypeOrSubtype)) {
|
||||
parameter.reportIncorrectInline(KtTokens.NOINLINE_KEYWORD, diagnosticHolder)
|
||||
parameter.reportIncorrectInline(KtTokens.CROSSINLINE_KEYWORD, diagnosticHolder)
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ package org.jetbrains.kotlin.resolve.calls
|
||||
import com.google.common.collect.Lists
|
||||
import com.google.common.collect.Sets
|
||||
import org.jetbrains.kotlin.builtins.ReflectionTypes
|
||||
import org.jetbrains.kotlin.builtins.isExactExtensionFunctionType
|
||||
import org.jetbrains.kotlin.builtins.isExtensionFunctionType
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.diagnostics.Errors
|
||||
import org.jetbrains.kotlin.diagnostics.Errors.SUPER_CANT_BE_EXTENSION_RECEIVER
|
||||
@@ -280,7 +280,7 @@ class CandidateResolver(
|
||||
candidateCall.extensionReceiver != null &&
|
||||
candidateCall.dispatchReceiver != null
|
||||
) {
|
||||
if (call.dispatchReceiver == candidateCall.dispatchReceiver && !call.dispatchReceiver.type.isExactExtensionFunctionType) {
|
||||
if (call.dispatchReceiver == candidateCall.dispatchReceiver && !call.dispatchReceiver.type.isExtensionFunctionType) {
|
||||
tracing.nonExtensionFunctionCalledAsExtension(trace)
|
||||
return@checkAndReport OTHER_ERROR
|
||||
}
|
||||
|
||||
+4
-4
@@ -17,7 +17,7 @@
|
||||
package org.jetbrains.kotlin.resolve.calls
|
||||
|
||||
import org.jetbrains.kotlin.builtins.ReflectionTypes
|
||||
import org.jetbrains.kotlin.builtins.isFunctionOrExtensionFunctionType
|
||||
import org.jetbrains.kotlin.builtins.isFunctionTypeOrSubtype
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
||||
@@ -238,7 +238,7 @@ class GenericCandidateResolver(private val argumentTypeResolver: ArgumentTypeRes
|
||||
) = if (!TypeUtils.noExpectedType(context.expectedType) &&
|
||||
ownerReturnType != null &&
|
||||
TypeUtils.isTypeParameter(ownerReturnType) &&
|
||||
literalExpectedType.isFunctionOrExtensionFunctionType &&
|
||||
literalExpectedType.isFunctionTypeOrSubtype &&
|
||||
getReturnTypeForCallable(literalExpectedType) == ownerReturnType)
|
||||
context.expectedType
|
||||
else DONT_CARE
|
||||
@@ -258,7 +258,7 @@ class GenericCandidateResolver(private val argumentTypeResolver: ArgumentTypeRes
|
||||
if (expectedType == null || TypeUtils.isDontCarePlaceholder(expectedType)) {
|
||||
expectedType = argumentTypeResolver.getShapeTypeOfFunctionLiteral(functionLiteral, context.scope, context.trace, false)
|
||||
}
|
||||
if (expectedType == null || !expectedType.isFunctionOrExtensionFunctionType || hasUnknownFunctionParameter(expectedType)) {
|
||||
if (expectedType == null || !expectedType.isFunctionTypeOrSubtype || hasUnknownFunctionParameter(expectedType)) {
|
||||
return
|
||||
}
|
||||
val dataFlowInfoForArguments = context.candidateCall.dataFlowInfoForArguments
|
||||
@@ -328,7 +328,7 @@ class GenericCandidateResolver(private val argumentTypeResolver: ArgumentTypeRes
|
||||
return substitutedType
|
||||
|
||||
val shapeType = argumentTypeResolver.getShapeTypeOfCallableReference(callableReference, context, false)
|
||||
if (shapeType != null && shapeType.isFunctionOrExtensionFunctionType && !hasUnknownFunctionParameter(shapeType))
|
||||
if (shapeType != null && shapeType.isFunctionTypeOrSubtype && !hasUnknownFunctionParameter(shapeType))
|
||||
return shapeType
|
||||
|
||||
return null
|
||||
|
||||
+1
-1
@@ -235,7 +235,7 @@ class InlineChecker implements CallChecker {
|
||||
boolean isInvoke =
|
||||
descriptor.getName().equals(OperatorNameConventions.INVOKE) &&
|
||||
containingDeclaration instanceof ClassDescriptor &&
|
||||
FunctionTypesKt.isExactFunctionOrExtensionFunctionType(((ClassDescriptor) containingDeclaration).getDefaultType());
|
||||
FunctionTypesKt.isFunctionType(((ClassDescriptor) containingDeclaration).getDefaultType());
|
||||
|
||||
return isInvoke || InlineUtil.isInline(descriptor);
|
||||
}
|
||||
|
||||
+2
-2
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.resolve.calls.checkers
|
||||
|
||||
import org.jetbrains.kotlin.builtins.isExactExtensionFunctionType
|
||||
import org.jetbrains.kotlin.builtins.isExtensionFunctionType
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.diagnostics.Errors
|
||||
import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext
|
||||
@@ -30,7 +30,7 @@ class InvokeConventionChecker : CallChecker {
|
||||
val functionCall = resolvedCall.functionCall
|
||||
val variableCall = resolvedCall.variableCall
|
||||
if (functionCall.dispatchReceiver != null && functionCall.extensionReceiver != null &&
|
||||
variableCall.resultingDescriptor.type.isExactExtensionFunctionType) {
|
||||
variableCall.resultingDescriptor.type.isExtensionFunctionType) {
|
||||
if (variableCall.dispatchReceiver is ExpressionReceiver || variableCall.extensionReceiver is ExpressionReceiver) {
|
||||
val callElement = variableCall.call.callElement
|
||||
context.trace.report(Errors.INVOKE_ON_EXTENSION_FUNCTION_WITH_EXPLICIT_DISPATCH_RECEIVER.on(callElement))
|
||||
|
||||
+1
-1
@@ -87,7 +87,7 @@ public class TracingStrategyForInvoke extends AbstractTracingStrategy {
|
||||
}
|
||||
|
||||
private void functionExpectedOrNoReceiverAllowed(BindingTrace trace) {
|
||||
if (FunctionTypesKt.isFunctionType(calleeType)) {
|
||||
if (FunctionTypesKt.isNonExtensionFunctionType(calleeType)) {
|
||||
trace.report(NO_RECEIVER_ALLOWED.on(reference));
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -36,7 +36,7 @@ public class InlineUtil {
|
||||
public static boolean isInlineLambdaParameter(@NotNull ParameterDescriptor valueParameterOrReceiver) {
|
||||
return !(valueParameterOrReceiver instanceof ValueParameterDescriptor
|
||||
&& ((ValueParameterDescriptor) valueParameterOrReceiver).isNoinline()) &&
|
||||
FunctionTypesKt.isExactFunctionOrExtensionFunctionType(valueParameterOrReceiver.getOriginal().getType());
|
||||
FunctionTypesKt.isFunctionType(valueParameterOrReceiver.getOriginal().getType());
|
||||
}
|
||||
|
||||
public static boolean isInline(@Nullable DeclarationDescriptor descriptor) {
|
||||
|
||||
+2
-2
@@ -21,7 +21,7 @@ import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.builtins.createFunctionType
|
||||
import org.jetbrains.kotlin.builtins.getReturnTypeFromFunctionType
|
||||
import org.jetbrains.kotlin.builtins.isFunctionOrExtensionFunctionType
|
||||
import org.jetbrains.kotlin.builtins.isFunctionTypeOrSubtype
|
||||
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
@@ -140,7 +140,7 @@ internal class FunctionsTypingVisitor(facade: ExpressionTypingInternals) : Expre
|
||||
if (!expression.functionLiteral.hasBody()) return null
|
||||
|
||||
val expectedType = context.expectedType
|
||||
val functionTypeExpected = !noExpectedType(expectedType) && expectedType.isFunctionOrExtensionFunctionType
|
||||
val functionTypeExpected = !noExpectedType(expectedType) && expectedType.isFunctionTypeOrSubtype
|
||||
|
||||
val functionDescriptor = createFunctionLiteralDescriptor(expression, context)
|
||||
expression.valueParameters.forEach {
|
||||
|
||||
+2
-3
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.resolve.calls.tower
|
||||
|
||||
import org.jetbrains.kotlin.builtins.isExactExtensionFunctionType
|
||||
import org.jetbrains.kotlin.builtins.isExtensionFunctionType
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind
|
||||
import org.jetbrains.kotlin.resolve.calls.tasks.createSynthesizedInvokes
|
||||
@@ -25,7 +25,6 @@ import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||
import java.util.*
|
||||
|
||||
|
||||
abstract class AbstractInvokeTowerProcessor<C>(
|
||||
protected val functionContext: TowerContext<C>,
|
||||
private val variableProcessor: ScopeTowerProcessor<C>
|
||||
@@ -141,7 +140,7 @@ private class InvokeExtensionScopeTowerProcessor<C>(
|
||||
private fun ScopeTower.getExtensionInvokeCandidateDescriptor(
|
||||
extensionFunctionReceiver: ReceiverValue
|
||||
): CandidateWithBoundDispatchReceiver<FunctionDescriptor>? {
|
||||
if (!extensionFunctionReceiver.type.isExactExtensionFunctionType) return null
|
||||
if (!extensionFunctionReceiver.type.isExtensionFunctionType) return null
|
||||
|
||||
val invokeDescriptor = extensionFunctionReceiver.type.memberScope.getContributedFunctions(OperatorNameConventions.INVOKE, location).single()
|
||||
val synthesizedInvoke = createSynthesizedInvokes(listOf(invokeDescriptor)).single()
|
||||
|
||||
Reference in New Issue
Block a user