From bdb7de142a30cf629d8450a31285b416b265c96d Mon Sep 17 00:00:00 2001 From: Svetlana Isakova Date: Thu, 3 May 2012 16:15:08 +0400 Subject: [PATCH] Member 'invoke' of function class should be abstract --- .../jet/lang/descriptors/FunctionDescriptorUtil.java | 8 +++++--- .../jetbrains/jet/lang/resolve/calls/CallResolver.java | 2 +- .../jet/lang/types/lang/JetStandardClasses.java | 4 ++-- .../diagnostics/tests/override/ExtendFunctionClass.jet | 9 +++++++++ 4 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/override/ExtendFunctionClass.jet diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/FunctionDescriptorUtil.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/FunctionDescriptorUtil.java index 3e5650d8ee6..e1cd4083a61 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/FunctionDescriptorUtil.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/FunctionDescriptorUtil.java @@ -119,15 +119,17 @@ public class FunctionDescriptorUtil { return parameterScope; } - public static void initializeFromFunctionType(@NotNull FunctionDescriptorImpl functionDescriptor, @NotNull JetType functionType, @NotNull ReceiverDescriptor expectedThisObject) { + public static void initializeFromFunctionType(@NotNull FunctionDescriptorImpl functionDescriptor, @NotNull JetType functionType, @NotNull ReceiverDescriptor expectedThisObject, + @NotNull Modality modality, @NotNull Visibility visibility) { + assert JetStandardClasses.isFunctionType(functionType); functionDescriptor.initialize(JetStandardClasses.getReceiverType(functionType), expectedThisObject, Collections.emptyList(), JetStandardClasses.getValueParameters(functionDescriptor, functionType), JetStandardClasses.getReturnTypeFromFunctionType(functionType), - Modality.FINAL, - Visibilities.PUBLIC); + modality, + visibility); } public static D alphaConvertTypeParameters(D candidate) { diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallResolver.java index 2be3d560873..2cd629a531a 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallResolver.java @@ -221,7 +221,7 @@ public class CallResolver { } FunctionDescriptorImpl functionDescriptor = new ExpressionAsFunctionDescriptor(context.scope.getContainingDeclaration(), "[for expression " + calleeExpression.getText() + "]"); - FunctionDescriptorUtil.initializeFromFunctionType(functionDescriptor, calleeType, NO_RECEIVER); + FunctionDescriptorUtil.initializeFromFunctionType(functionDescriptor, calleeType, NO_RECEIVER, Modality.FINAL, Visibilities.LOCAL); ResolutionCandidate resolutionCandidate = ResolutionCandidate.create(functionDescriptor); resolutionCandidate.setReceiverArgument(context.call.getExplicitReceiver()); resolutionCandidate.setExplicitReceiverKind(ExplicitReceiverKind.RECEIVER_ARGUMENT); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/lang/JetStandardClasses.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/lang/JetStandardClasses.java index c34da66c0f7..94bcfc1952f 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/lang/JetStandardClasses.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/lang/JetStandardClasses.java @@ -201,7 +201,7 @@ public class JetStandardClasses { typeParameters, Collections.singleton(getAnyType()), scopeForInvoke, Collections.emptySet(), null); FUNCTION_TYPE_CONSTRUCTORS.add(FUNCTION[i].getTypeConstructor()); - FunctionDescriptorUtil.initializeFromFunctionType(invoke, function.getDefaultType(), new ClassReceiver(FUNCTION[i])); + FunctionDescriptorUtil.initializeFromFunctionType(invoke, function.getDefaultType(), new ClassReceiver(FUNCTION[i]), Modality.ABSTRACT, Visibilities.PUBLIC); ClassDescriptorImpl receiverFunction = new ClassDescriptorImpl( STANDARD_CLASSES_NAMESPACE, @@ -219,7 +219,7 @@ public class JetStandardClasses { parameters, Collections.singleton(getAnyType()), scopeForInvokeWithReceiver, Collections.emptySet(), null); RECEIVER_FUNCTION_TYPE_CONSTRUCTORS.add(RECEIVER_FUNCTION[i].getTypeConstructor()); - FunctionDescriptorUtil.initializeFromFunctionType(invokeWithReceiver, receiverFunction.getDefaultType(), new ClassReceiver(RECEIVER_FUNCTION[i])); + FunctionDescriptorUtil.initializeFromFunctionType(invokeWithReceiver, receiverFunction.getDefaultType(), new ClassReceiver(RECEIVER_FUNCTION[i]), Modality.ABSTRACT, Visibilities.PUBLIC); } } diff --git a/compiler/testData/diagnostics/tests/override/ExtendFunctionClass.jet b/compiler/testData/diagnostics/tests/override/ExtendFunctionClass.jet new file mode 100644 index 00000000000..fe37f3e17f5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/ExtendFunctionClass.jet @@ -0,0 +1,9 @@ +package extendFunctionClass + +class A : (Int) -> Int { + +} + +class B : Function1 { + override fun invoke(p0 : Int) = p0 +}