Forbidden old invokeExtension convention.
This commit is contained in:
@@ -453,8 +453,6 @@ public interface Errors {
|
||||
DiagnosticFactory1<JetExpression, JetType> MISSING_RECEIVER = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory0<JetExpression> NO_RECEIVER_ALLOWED = DiagnosticFactory0.create(ERROR);
|
||||
|
||||
DiagnosticFactory0<JetExpression> FREE_FUNCTION_CALLED_AS_EXTENSION = DiagnosticFactory0.create(ERROR);
|
||||
|
||||
// Call resolution
|
||||
|
||||
DiagnosticFactory1<JetExpression, String> ILLEGAL_SELECTOR = DiagnosticFactory1.create(ERROR);
|
||||
@@ -475,6 +473,7 @@ public interface Errors {
|
||||
DiagnosticFactory1<PsiElement, Collection<? extends ResolvedCall<?>>> NONE_APPLICABLE = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<PsiElement, Collection<? extends ResolvedCall<?>>> CANNOT_COMPLETE_RESOLVE = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<PsiElement, Collection<? extends ResolvedCall<?>>> UNRESOLVED_REFERENCE_WRONG_RECEIVER = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<PsiElement, JetExpression> INVOKE_EXTENSION_ON_NOT_EXTENSION_FUNCTION = DiagnosticFactory1.create(ERROR);
|
||||
|
||||
DiagnosticFactory1<PsiElement, TypeParameterDescriptor> TYPE_PARAMETER_AS_REIFIED = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<PsiElement, JetType> REIFIED_TYPE_FORBIDDEN_SUBSTITUTION = DiagnosticFactory1.create(ERROR);
|
||||
|
||||
+1
-2
@@ -591,13 +591,12 @@ public class DefaultErrorMessages {
|
||||
MAP.put(NONE_APPLICABLE, "None of the following functions can be called with the arguments supplied: {0}", AMBIGUOUS_CALLS);
|
||||
MAP.put(CANNOT_COMPLETE_RESOLVE, "Cannot choose among the following candidates without completing type inference: {0}", AMBIGUOUS_CALLS);
|
||||
MAP.put(UNRESOLVED_REFERENCE_WRONG_RECEIVER, "Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: {0}", AMBIGUOUS_CALLS);
|
||||
MAP.put(INVOKE_EXTENSION_ON_NOT_EXTENSION_FUNCTION, "Impossible call as extension because {0} is not an extension function.", ELEMENT_TEXT);
|
||||
|
||||
MAP.put(NO_VALUE_FOR_PARAMETER, "No value passed for parameter {0}", NAME);
|
||||
MAP.put(MISSING_RECEIVER, "A receiver of type {0} is required", RENDER_TYPE);
|
||||
MAP.put(NO_RECEIVER_ALLOWED, "No receiver can be passed to this function or property");
|
||||
|
||||
MAP.put(FREE_FUNCTION_CALLED_AS_EXTENSION, "The function cannot be called as an extension function");
|
||||
|
||||
MAP.put(CREATING_AN_INSTANCE_OF_ABSTRACT_CLASS, "Cannot create an instance of an abstract class");
|
||||
|
||||
MAP.put(TYPE_INFERENCE_CONFLICTING_SUBSTITUTIONS, "Type inference failed: {0}", TYPE_INFERENCE_CONFLICTING_SUBSTITUTIONS_RENDERER);
|
||||
|
||||
@@ -267,14 +267,18 @@ public class CandidateResolver(
|
||||
}
|
||||
|
||||
private fun CallCandidateResolutionContext<*>.checkNonExtensionCalledWithReceiver() = checkAndReport {
|
||||
if (isSynthesizedInvoke(candidateCall.getCandidateDescriptor())
|
||||
&& !KotlinBuiltIns.isExtensionFunctionType(candidateCall.getDispatchReceiver().getType())
|
||||
val call = candidateCall.call
|
||||
if (call is CallTransformer.CallForImplicitInvoke && candidateCall.extensionReceiver.exists()
|
||||
&& candidateCall.dispatchReceiver.exists()
|
||||
) {
|
||||
tracing.freeFunctionCalledAsExtension(trace)
|
||||
OTHER_ERROR
|
||||
} else {
|
||||
SUCCESS
|
||||
if (call.dispatchReceiver == candidateCall.dispatchReceiver
|
||||
&& !KotlinBuiltIns.isExactExtensionFunctionType(call.dispatchReceiver.type)
|
||||
) {
|
||||
tracing.nonExtensionFunctionCalledAsExtension(trace)
|
||||
return@checkAndReport OTHER_ERROR
|
||||
}
|
||||
}
|
||||
SUCCESS
|
||||
}
|
||||
|
||||
private fun getReceiverSuper(receiver: ReceiverValue): JetSuperExpression? {
|
||||
|
||||
+2
-2
@@ -253,7 +253,7 @@ public abstract class AbstractTracingStrategy implements TracingStrategy {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void freeFunctionCalledAsExtension(@NotNull BindingTrace trace) {
|
||||
trace.report(FREE_FUNCTION_CALLED_AS_EXTENSION.on(reference));
|
||||
public void nonExtensionFunctionCalledAsExtension(@NotNull BindingTrace trace) {
|
||||
trace.report(INVOKE_EXTENSION_ON_NOT_EXTENSION_FUNCTION.on(reference, reference));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ public interface TracingStrategy {
|
||||
public void typeInferenceFailed(@NotNull BindingTrace trace, @NotNull InferenceErrorData inferenceErrorData) {}
|
||||
|
||||
@Override
|
||||
public void freeFunctionCalledAsExtension(@NotNull BindingTrace trace) { }
|
||||
public void nonExtensionFunctionCalledAsExtension(@NotNull BindingTrace trace) { }
|
||||
};
|
||||
|
||||
void bindCall(@NotNull BindingTrace trace, @NotNull Call call);
|
||||
@@ -153,5 +153,5 @@ public interface TracingStrategy {
|
||||
|
||||
void typeInferenceFailed(@NotNull BindingTrace trace, @NotNull InferenceErrorData inferenceErrorData);
|
||||
|
||||
void freeFunctionCalledAsExtension(@NotNull BindingTrace trace);
|
||||
void nonExtensionFunctionCalledAsExtension(@NotNull BindingTrace trace);
|
||||
}
|
||||
|
||||
+1
-1
@@ -534,7 +534,7 @@ public class ControlStructureTypingUtils {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void freeFunctionCalledAsExtension(@NotNull BindingTrace trace) {
|
||||
public void nonExtensionFunctionCalledAsExtension(@NotNull BindingTrace trace) {
|
||||
logError();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user