Don't report "cannot infer visibility" on property accessors
If the diagnostic is already reported on the corresponding property, no need to report it again for accessors
This commit is contained in:
@@ -19,7 +19,6 @@ package org.jetbrains.jet.lang.resolve;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
@@ -178,9 +177,16 @@ public class OverrideResolver {
|
||||
return new Function1<CallableMemberDescriptor, Unit>() {
|
||||
@Override
|
||||
public Unit invoke(@NotNull CallableMemberDescriptor descriptor) {
|
||||
DeclarationDescriptor reportOn = descriptor.getKind() == FAKE_OVERRIDE || descriptor.getKind() == DELEGATION
|
||||
? DescriptorUtils.getParentOfType(descriptor, ClassDescriptor.class)
|
||||
: descriptor;
|
||||
DeclarationDescriptor reportOn;
|
||||
if (descriptor.getKind() == FAKE_OVERRIDE || descriptor.getKind() == DELEGATION) {
|
||||
reportOn = DescriptorUtils.getParentOfType(descriptor, ClassDescriptor.class);
|
||||
}
|
||||
else if (descriptor instanceof PropertyAccessorDescriptor && ((PropertyAccessorDescriptor) descriptor).isDefault()) {
|
||||
reportOn = ((PropertyAccessorDescriptor) descriptor).getCorrespondingProperty();
|
||||
}
|
||||
else {
|
||||
reportOn = descriptor;
|
||||
}
|
||||
//noinspection ConstantConditions
|
||||
PsiElement element = BindingContextUtils.descriptorToDeclaration(trace.getBindingContext(), reportOn);
|
||||
if (element instanceof JetDeclaration) {
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
trait T {
|
||||
internal var foo: Long
|
||||
}
|
||||
|
||||
trait U {
|
||||
protected var foo: Long
|
||||
}
|
||||
|
||||
trait V : T, U {
|
||||
<!CANNOT_INFER_VISIBILITY!>override var foo: Long<!>
|
||||
}
|
||||
|
||||
trait <!CANNOT_INFER_VISIBILITY!>W<!> : T, U
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
trait T {
|
||||
public var foo: Short
|
||||
internal set
|
||||
}
|
||||
|
||||
trait U {
|
||||
public var foo: Short
|
||||
protected set
|
||||
}
|
||||
|
||||
trait V : T, U {
|
||||
<!CANNOT_INFER_VISIBILITY!>override var foo: Short<!>
|
||||
}
|
||||
@@ -5242,6 +5242,16 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
||||
doTest("compiler/testData/diagnostics/tests/override/AllProtectedFromSupertypes.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("CannotInferVisibilityForProperty.kt")
|
||||
public void testCannotInferVisibilityForProperty() throws Exception {
|
||||
doTest("compiler/testData/diagnostics/tests/override/CannotInferVisibilityForProperty.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("CannotInferVisibilityForPropertySetter.kt")
|
||||
public void testCannotInferVisibilityForPropertySetter() throws Exception {
|
||||
doTest("compiler/testData/diagnostics/tests/override/CannotInferVisibilityForPropertySetter.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("ComplexValRedeclaration.kt")
|
||||
public void testComplexValRedeclaration() throws Exception {
|
||||
doTest("compiler/testData/diagnostics/tests/override/ComplexValRedeclaration.kt");
|
||||
|
||||
+1
-8
@@ -18,7 +18,6 @@ package org.jetbrains.jet.lang.descriptors.impl;
|
||||
|
||||
import kotlin.Function0;
|
||||
import kotlin.Function1;
|
||||
import kotlin.Unit;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
@@ -225,13 +224,7 @@ public class EnumEntrySyntheticClassDescriptor extends ClassDescriptorBase {
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void addToScope(@NotNull CallableMemberDescriptor fakeOverride) {
|
||||
OverridingUtil.resolveUnknownVisibilityForMember(fakeOverride, new Function1<CallableMemberDescriptor, Unit>() {
|
||||
@Override
|
||||
public Unit invoke(@NotNull CallableMemberDescriptor descriptor) {
|
||||
// Do nothing
|
||||
return Unit.VALUE;
|
||||
}
|
||||
});
|
||||
OverridingUtil.resolveUnknownVisibilityForMember(fakeOverride, null);
|
||||
result.add((D) fakeOverride);
|
||||
}
|
||||
|
||||
|
||||
@@ -367,7 +367,7 @@ public class OverridingUtil {
|
||||
|
||||
public static void resolveUnknownVisibilityForMember(
|
||||
@NotNull CallableMemberDescriptor memberDescriptor,
|
||||
@NotNull Function1<CallableMemberDescriptor, Unit> cannotInferVisibility
|
||||
@Nullable Function1<CallableMemberDescriptor, Unit> cannotInferVisibility
|
||||
) {
|
||||
for (CallableMemberDescriptor descriptor : memberDescriptor.getOverriddenDescriptors()) {
|
||||
if (descriptor.getVisibility() == Visibilities.INHERITED) {
|
||||
@@ -379,11 +379,13 @@ public class OverridingUtil {
|
||||
return;
|
||||
}
|
||||
|
||||
Visibility visibilityToInherit = computeVisibilityToInherit(memberDescriptor, cannotInferVisibility);
|
||||
Visibility maxVisibility = computeVisibilityToInherit(memberDescriptor, cannotInferVisibility);
|
||||
Visibility visibilityToInherit = maxVisibility == null ? Visibilities.PUBLIC : maxVisibility;
|
||||
if (memberDescriptor instanceof PropertyDescriptorImpl) {
|
||||
((PropertyDescriptorImpl) memberDescriptor).setVisibility(visibilityToInherit);
|
||||
for (PropertyAccessorDescriptor accessor : ((PropertyDescriptor) memberDescriptor).getAccessors()) {
|
||||
resolveUnknownVisibilityForMember(accessor, cannotInferVisibility);
|
||||
// If we couldn't infer visibility for property, the diagnostic is already reported, no need to report it again on accessors
|
||||
resolveUnknownVisibilityForMember(accessor, maxVisibility == null ? null : cannotInferVisibility);
|
||||
}
|
||||
}
|
||||
else if (memberDescriptor instanceof FunctionDescriptorImpl) {
|
||||
@@ -395,15 +397,17 @@ public class OverridingUtil {
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Nullable
|
||||
private static Visibility computeVisibilityToInherit(
|
||||
@NotNull CallableMemberDescriptor memberDescriptor,
|
||||
@NotNull Function1<CallableMemberDescriptor, Unit> cannotInferVisibility
|
||||
@Nullable Function1<CallableMemberDescriptor, Unit> cannotInferVisibility
|
||||
) {
|
||||
Visibility maxVisibility = findMaxVisibility(memberDescriptor.getOverriddenDescriptors());
|
||||
if (maxVisibility == null) {
|
||||
cannotInferVisibility.invoke(memberDescriptor);
|
||||
return Visibilities.PUBLIC;
|
||||
if (cannotInferVisibility != null) {
|
||||
cannotInferVisibility.invoke(memberDescriptor);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
if (memberDescriptor.getKind() == CallableMemberDescriptor.Kind.FAKE_OVERRIDE) {
|
||||
return maxVisibility;
|
||||
|
||||
+3
-15
@@ -19,7 +19,6 @@ package org.jetbrains.jet.descriptors.serialization.descriptors;
|
||||
import kotlin.Function0;
|
||||
import kotlin.Function1;
|
||||
import kotlin.KotlinPackage;
|
||||
import kotlin.Unit;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.descriptors.serialization.*;
|
||||
@@ -282,12 +281,7 @@ public class DeserializedClassDescriptor extends AbstractClassDescriptor impleme
|
||||
OverridingUtil.DescriptorSink sink = new OverridingUtil.DescriptorSink() {
|
||||
@Override
|
||||
public void addToScope(@NotNull CallableMemberDescriptor fakeOverride) {
|
||||
OverridingUtil.resolveUnknownVisibilityForMember(fakeOverride, new Function1<CallableMemberDescriptor, Unit>() {
|
||||
@Override
|
||||
public Unit invoke(@NotNull CallableMemberDescriptor descriptor) {
|
||||
throw new IllegalStateException("Cannot infer visibility for " + descriptor + " in " + classObject);
|
||||
}
|
||||
});
|
||||
OverridingUtil.resolveUnknownVisibilityForMember(fakeOverride, null);
|
||||
classObject.getBuilder().addFunctionDescriptor((SimpleFunctionDescriptor) fakeOverride);
|
||||
}
|
||||
|
||||
@@ -435,14 +429,8 @@ public class DeserializedClassDescriptor extends AbstractClassDescriptor impleme
|
||||
new OverridingUtil.DescriptorSink() {
|
||||
@Override
|
||||
public void addToScope(@NotNull CallableMemberDescriptor fakeOverride) {
|
||||
OverridingUtil.resolveUnknownVisibilityForMember(fakeOverride, new Function1<CallableMemberDescriptor, Unit>() {
|
||||
@Override
|
||||
public Unit invoke(@NotNull CallableMemberDescriptor descriptor) {
|
||||
// Do nothing
|
||||
// TODO: do something
|
||||
return Unit.VALUE;
|
||||
}
|
||||
});
|
||||
// TODO: report "cannot infer visibility"
|
||||
OverridingUtil.resolveUnknownVisibilityForMember(fakeOverride, null);
|
||||
//noinspection unchecked
|
||||
result.add((D) fakeOverride);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user