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.Lists;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
import com.intellij.lang.ASTNode;
|
|
||||||
import com.intellij.psi.PsiElement;
|
import com.intellij.psi.PsiElement;
|
||||||
import com.intellij.util.Function;
|
import com.intellij.util.Function;
|
||||||
import com.intellij.util.containers.ContainerUtil;
|
import com.intellij.util.containers.ContainerUtil;
|
||||||
@@ -178,9 +177,16 @@ public class OverrideResolver {
|
|||||||
return new Function1<CallableMemberDescriptor, Unit>() {
|
return new Function1<CallableMemberDescriptor, Unit>() {
|
||||||
@Override
|
@Override
|
||||||
public Unit invoke(@NotNull CallableMemberDescriptor descriptor) {
|
public Unit invoke(@NotNull CallableMemberDescriptor descriptor) {
|
||||||
DeclarationDescriptor reportOn = descriptor.getKind() == FAKE_OVERRIDE || descriptor.getKind() == DELEGATION
|
DeclarationDescriptor reportOn;
|
||||||
? DescriptorUtils.getParentOfType(descriptor, ClassDescriptor.class)
|
if (descriptor.getKind() == FAKE_OVERRIDE || descriptor.getKind() == DELEGATION) {
|
||||||
: descriptor;
|
reportOn = DescriptorUtils.getParentOfType(descriptor, ClassDescriptor.class);
|
||||||
|
}
|
||||||
|
else if (descriptor instanceof PropertyAccessorDescriptor && ((PropertyAccessorDescriptor) descriptor).isDefault()) {
|
||||||
|
reportOn = ((PropertyAccessorDescriptor) descriptor).getCorrespondingProperty();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
reportOn = descriptor;
|
||||||
|
}
|
||||||
//noinspection ConstantConditions
|
//noinspection ConstantConditions
|
||||||
PsiElement element = BindingContextUtils.descriptorToDeclaration(trace.getBindingContext(), reportOn);
|
PsiElement element = BindingContextUtils.descriptorToDeclaration(trace.getBindingContext(), reportOn);
|
||||||
if (element instanceof JetDeclaration) {
|
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");
|
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")
|
@TestMetadata("ComplexValRedeclaration.kt")
|
||||||
public void testComplexValRedeclaration() throws Exception {
|
public void testComplexValRedeclaration() throws Exception {
|
||||||
doTest("compiler/testData/diagnostics/tests/override/ComplexValRedeclaration.kt");
|
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.Function0;
|
||||||
import kotlin.Function1;
|
import kotlin.Function1;
|
||||||
import kotlin.Unit;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.descriptors.*;
|
import org.jetbrains.jet.lang.descriptors.*;
|
||||||
@@ -225,13 +224,7 @@ public class EnumEntrySyntheticClassDescriptor extends ClassDescriptorBase {
|
|||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void addToScope(@NotNull CallableMemberDescriptor fakeOverride) {
|
public void addToScope(@NotNull CallableMemberDescriptor fakeOverride) {
|
||||||
OverridingUtil.resolveUnknownVisibilityForMember(fakeOverride, new Function1<CallableMemberDescriptor, Unit>() {
|
OverridingUtil.resolveUnknownVisibilityForMember(fakeOverride, null);
|
||||||
@Override
|
|
||||||
public Unit invoke(@NotNull CallableMemberDescriptor descriptor) {
|
|
||||||
// Do nothing
|
|
||||||
return Unit.VALUE;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
result.add((D) fakeOverride);
|
result.add((D) fakeOverride);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -367,7 +367,7 @@ public class OverridingUtil {
|
|||||||
|
|
||||||
public static void resolveUnknownVisibilityForMember(
|
public static void resolveUnknownVisibilityForMember(
|
||||||
@NotNull CallableMemberDescriptor memberDescriptor,
|
@NotNull CallableMemberDescriptor memberDescriptor,
|
||||||
@NotNull Function1<CallableMemberDescriptor, Unit> cannotInferVisibility
|
@Nullable Function1<CallableMemberDescriptor, Unit> cannotInferVisibility
|
||||||
) {
|
) {
|
||||||
for (CallableMemberDescriptor descriptor : memberDescriptor.getOverriddenDescriptors()) {
|
for (CallableMemberDescriptor descriptor : memberDescriptor.getOverriddenDescriptors()) {
|
||||||
if (descriptor.getVisibility() == Visibilities.INHERITED) {
|
if (descriptor.getVisibility() == Visibilities.INHERITED) {
|
||||||
@@ -379,11 +379,13 @@ public class OverridingUtil {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Visibility visibilityToInherit = computeVisibilityToInherit(memberDescriptor, cannotInferVisibility);
|
Visibility maxVisibility = computeVisibilityToInherit(memberDescriptor, cannotInferVisibility);
|
||||||
|
Visibility visibilityToInherit = maxVisibility == null ? Visibilities.PUBLIC : maxVisibility;
|
||||||
if (memberDescriptor instanceof PropertyDescriptorImpl) {
|
if (memberDescriptor instanceof PropertyDescriptorImpl) {
|
||||||
((PropertyDescriptorImpl) memberDescriptor).setVisibility(visibilityToInherit);
|
((PropertyDescriptorImpl) memberDescriptor).setVisibility(visibilityToInherit);
|
||||||
for (PropertyAccessorDescriptor accessor : ((PropertyDescriptor) memberDescriptor).getAccessors()) {
|
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) {
|
else if (memberDescriptor instanceof FunctionDescriptorImpl) {
|
||||||
@@ -395,15 +397,17 @@ public class OverridingUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@Nullable
|
||||||
private static Visibility computeVisibilityToInherit(
|
private static Visibility computeVisibilityToInherit(
|
||||||
@NotNull CallableMemberDescriptor memberDescriptor,
|
@NotNull CallableMemberDescriptor memberDescriptor,
|
||||||
@NotNull Function1<CallableMemberDescriptor, Unit> cannotInferVisibility
|
@Nullable Function1<CallableMemberDescriptor, Unit> cannotInferVisibility
|
||||||
) {
|
) {
|
||||||
Visibility maxVisibility = findMaxVisibility(memberDescriptor.getOverriddenDescriptors());
|
Visibility maxVisibility = findMaxVisibility(memberDescriptor.getOverriddenDescriptors());
|
||||||
if (maxVisibility == null) {
|
if (maxVisibility == null) {
|
||||||
cannotInferVisibility.invoke(memberDescriptor);
|
if (cannotInferVisibility != null) {
|
||||||
return Visibilities.PUBLIC;
|
cannotInferVisibility.invoke(memberDescriptor);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
if (memberDescriptor.getKind() == CallableMemberDescriptor.Kind.FAKE_OVERRIDE) {
|
if (memberDescriptor.getKind() == CallableMemberDescriptor.Kind.FAKE_OVERRIDE) {
|
||||||
return maxVisibility;
|
return maxVisibility;
|
||||||
|
|||||||
+3
-15
@@ -19,7 +19,6 @@ package org.jetbrains.jet.descriptors.serialization.descriptors;
|
|||||||
import kotlin.Function0;
|
import kotlin.Function0;
|
||||||
import kotlin.Function1;
|
import kotlin.Function1;
|
||||||
import kotlin.KotlinPackage;
|
import kotlin.KotlinPackage;
|
||||||
import kotlin.Unit;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.descriptors.serialization.*;
|
import org.jetbrains.jet.descriptors.serialization.*;
|
||||||
@@ -282,12 +281,7 @@ public class DeserializedClassDescriptor extends AbstractClassDescriptor impleme
|
|||||||
OverridingUtil.DescriptorSink sink = new OverridingUtil.DescriptorSink() {
|
OverridingUtil.DescriptorSink sink = new OverridingUtil.DescriptorSink() {
|
||||||
@Override
|
@Override
|
||||||
public void addToScope(@NotNull CallableMemberDescriptor fakeOverride) {
|
public void addToScope(@NotNull CallableMemberDescriptor fakeOverride) {
|
||||||
OverridingUtil.resolveUnknownVisibilityForMember(fakeOverride, new Function1<CallableMemberDescriptor, Unit>() {
|
OverridingUtil.resolveUnknownVisibilityForMember(fakeOverride, null);
|
||||||
@Override
|
|
||||||
public Unit invoke(@NotNull CallableMemberDescriptor descriptor) {
|
|
||||||
throw new IllegalStateException("Cannot infer visibility for " + descriptor + " in " + classObject);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
classObject.getBuilder().addFunctionDescriptor((SimpleFunctionDescriptor) fakeOverride);
|
classObject.getBuilder().addFunctionDescriptor((SimpleFunctionDescriptor) fakeOverride);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -435,14 +429,8 @@ public class DeserializedClassDescriptor extends AbstractClassDescriptor impleme
|
|||||||
new OverridingUtil.DescriptorSink() {
|
new OverridingUtil.DescriptorSink() {
|
||||||
@Override
|
@Override
|
||||||
public void addToScope(@NotNull CallableMemberDescriptor fakeOverride) {
|
public void addToScope(@NotNull CallableMemberDescriptor fakeOverride) {
|
||||||
OverridingUtil.resolveUnknownVisibilityForMember(fakeOverride, new Function1<CallableMemberDescriptor, Unit>() {
|
// TODO: report "cannot infer visibility"
|
||||||
@Override
|
OverridingUtil.resolveUnknownVisibilityForMember(fakeOverride, null);
|
||||||
public Unit invoke(@NotNull CallableMemberDescriptor descriptor) {
|
|
||||||
// Do nothing
|
|
||||||
// TODO: do something
|
|
||||||
return Unit.VALUE;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
//noinspection unchecked
|
//noinspection unchecked
|
||||||
result.add((D) fakeOverride);
|
result.add((D) fakeOverride);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user