diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/OverrideResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/OverrideResolver.java index ecbc9cadbab..97af644f0b3 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/OverrideResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/OverrideResolver.java @@ -171,48 +171,48 @@ public class OverrideResolver { nameIdentifier = ((JetObjectDeclaration) klass).getNameIdentifier(); } -// for (CallableMemberDescriptor memberDescriptor : manyImpl) { -// context.getTrace().report(MANY_IMPL_MEMBER_NOT_IMPLEMENTED.on(nameIdentifier, klass, memberDescriptor)); -// break; -// } + for (CallableMemberDescriptor memberDescriptor : manyImpl) { + context.getTrace().report(MANY_IMPL_MEMBER_NOT_IMPLEMENTED.on(nameIdentifier, klass, memberDescriptor)); + break; + } if (classDescriptor.getModality() == Modality.ABSTRACT) { return; } -// for (CallableMemberDescriptor memberDescriptor : abstractNoImpl) { -// context.getTrace().report(ABSTRACT_MEMBER_NOT_IMPLEMENTED.on(nameIdentifier, klass, memberDescriptor)); -// break; -// } + for (CallableMemberDescriptor memberDescriptor : abstractNoImpl) { + context.getTrace().report(ABSTRACT_MEMBER_NOT_IMPLEMENTED.on(nameIdentifier, klass, memberDescriptor)); + break; + } - Set allOverriddenFunctions = Sets.newHashSet(); - Collection allDescriptors = classDescriptor.getDefaultType().getMemberScope().getAllDescriptors(); - for (DeclarationDescriptor descriptor : allDescriptors) { - if (descriptor instanceof FunctionDescriptor) { - FunctionDescriptor functionDescriptor = (FunctionDescriptor) descriptor; - if (functionDescriptor.getModality() != Modality.ABSTRACT) { - for (FunctionDescriptor overriddenDescriptor : functionDescriptor.getOverriddenDescriptors()) { - allOverriddenFunctions.add(overriddenDescriptor.getOriginal()); - } - } - } - } - boolean foundError = false; - for (DeclarationDescriptor descriptor : allDescriptors) { - if (descriptor instanceof FunctionDescriptor) { - FunctionDescriptor functionDescriptor = (FunctionDescriptor) descriptor; - if (functionDescriptor.getModality() == Modality.ABSTRACT && !allOverriddenFunctions.contains(functionDescriptor.getOriginal()) && !foundError && nameIdentifier != null) { - DeclarationDescriptor declarationDescriptor = functionDescriptor.getContainingDeclaration(); - if (declarationDescriptor != classDescriptor) { -// context.getTrace().getErrorHandler().genericError(nameIdentifier.getNode(), "Class '" + klass.getName() + "' must be declared abstract or implement abstract method '" + -// functionDescriptor.getName() + "' declared in " + declarationDescriptor.getName()); - context.getTrace().report(ABSTRACT_MEMBER_NOT_IMPLEMENTED.on(nameIdentifier, klass, functionDescriptor)); - foundError = true; - } - } - } - } +// Set allOverriddenFunctions = Sets.newHashSet(); +// Collection allDescriptors = classDescriptor.getDefaultType().getMemberScope().getAllDescriptors(); +// for (DeclarationDescriptor descriptor : allDescriptors) { +// if (descriptor instanceof FunctionDescriptor) { +// FunctionDescriptor functionDescriptor = (FunctionDescriptor) descriptor; +// if (functionDescriptor.getModality() != Modality.ABSTRACT) { +// for (FunctionDescriptor overriddenDescriptor : functionDescriptor.getOverriddenDescriptors()) { +// allOverriddenFunctions.add(overriddenDescriptor.getOriginal()); +// } +// } +// } +// } +// boolean foundError = false; +// for (DeclarationDescriptor descriptor : allDescriptors) { +// if (descriptor instanceof FunctionDescriptor) { +// FunctionDescriptor functionDescriptor = (FunctionDescriptor) descriptor; +// if (functionDescriptor.getModality() == Modality.ABSTRACT && !allOverriddenFunctions.contains(functionDescriptor.getOriginal()) && !foundError && nameIdentifier != null) { +// DeclarationDescriptor declarationDescriptor = functionDescriptor.getContainingDeclaration(); +// if (declarationDescriptor != classDescriptor) { +//// context.getTrace().getErrorHandler().genericError(nameIdentifier.getNode(), "Class '" + klass.getName() + "' must be declared abstract or implement abstract method '" + +//// functionDescriptor.getName() + "' declared in " + declarationDescriptor.getName()); +// context.getTrace().report(ABSTRACT_MEMBER_NOT_IMPLEMENTED.on(nameIdentifier, klass, functionDescriptor)); +// foundError = true; +// } +// } +// } +// } } private void checkOverride(CallableMemberDescriptor declared) { diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/OverridingUtil.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/OverridingUtil.java index 151461e145b..314f847b5ef 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/OverridingUtil.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/OverridingUtil.java @@ -85,6 +85,12 @@ public class OverridingUtil { @NotNull public static OverrideCompatibilityInfo isOverridableBy(@NotNull CallableDescriptor superDescriptor, @NotNull CallableDescriptor subDescriptor) { + if (superDescriptor instanceof FunctionDescriptor) { + if (subDescriptor instanceof PropertyDescriptor) return OverrideCompatibilityInfo.memberKindMismatch(); + } + if (superDescriptor instanceof PropertyDescriptor) { + if (subDescriptor instanceof FunctionDescriptor) return OverrideCompatibilityInfo.memberKindMismatch(); + } if (!superDescriptor.getName().equals(subDescriptor.getName())) { return OverrideCompatibilityInfo.nameMismatch(); } @@ -192,6 +198,11 @@ public class OverridingUtil { return new OverrideCompatibilityInfo(false, "valueParameterTypeMismatch"); // TODO } + @NotNull + public static OverrideCompatibilityInfo memberKindMismatch() { + return new OverrideCompatibilityInfo(false, "memberKindMismatch"); // TODO + } + @NotNull public static OverrideCompatibilityInfo returnTypeMismatch(JetType substitutedSuperReturnType, JetType unsubstitutedSubReturnType) { return new OverrideCompatibilityInfo(true, "returnTypeMismatch: " + unsubstitutedSubReturnType + " >< " + substitutedSuperReturnType); // TODO diff --git a/idea/testData/checkerWithErrorTypes/full/ValAndFunOverrideCompatibilityClash.jet b/idea/testData/checkerWithErrorTypes/full/ValAndFunOverrideCompatibilityClash.jet new file mode 100644 index 00000000000..f18974bb51f --- /dev/null +++ b/idea/testData/checkerWithErrorTypes/full/ValAndFunOverrideCompatibilityClash.jet @@ -0,0 +1,8 @@ +class Foo1() : java.util.ArrayList() + +open class Bar() { + fun v() : Int = 1 + val v : Int = 1 +} + +class Barr() : Bar() {}