Fix "Cannot infer visibility" for fake overrides
#KT-4785 Fixed
This commit is contained in:
+12
-6
@@ -145,24 +145,30 @@ public class PositioningStrategies {
|
|||||||
property.getTextRange().getStartOffset(), endOfSignatureElement.getTextRange().getEndOffset()));
|
property.getTextRange().getStartOffset(), endOfSignatureElement.getTextRange().getEndOffset()));
|
||||||
}
|
}
|
||||||
else if (element instanceof JetClass) {
|
else if (element instanceof JetClass) {
|
||||||
// primary constructor
|
PsiElement nameAsDeclaration = element.getNameIdentifier();
|
||||||
JetClass klass = (JetClass)element;
|
|
||||||
PsiElement nameAsDeclaration = klass.getNameIdentifier();
|
|
||||||
if (nameAsDeclaration == null) {
|
if (nameAsDeclaration == null) {
|
||||||
return markElement(klass);
|
return markElement(element);
|
||||||
}
|
}
|
||||||
PsiElement primaryConstructorParameterList = klass.getPrimaryConstructorParameterList();
|
PsiElement primaryConstructorParameterList = ((JetClass) element).getPrimaryConstructorParameterList();
|
||||||
if (primaryConstructorParameterList == null) {
|
if (primaryConstructorParameterList == null) {
|
||||||
return markRange(nameAsDeclaration.getTextRange());
|
return markRange(nameAsDeclaration.getTextRange());
|
||||||
}
|
}
|
||||||
return markRange(new TextRange(
|
return markRange(new TextRange(
|
||||||
nameAsDeclaration.getTextRange().getStartOffset(), primaryConstructorParameterList.getTextRange().getEndOffset()));
|
nameAsDeclaration.getTextRange().getStartOffset(), primaryConstructorParameterList.getTextRange().getEndOffset()));
|
||||||
}
|
}
|
||||||
|
else if (element instanceof JetObjectDeclaration) {
|
||||||
|
PsiElement nameAsDeclaration = element.getNameIdentifier();
|
||||||
|
if (nameAsDeclaration == null) {
|
||||||
|
return markElement(((JetObjectDeclaration) element).getObjectKeyword());
|
||||||
|
}
|
||||||
|
return markRange(nameAsDeclaration.getTextRange());
|
||||||
|
}
|
||||||
return super.mark(element);
|
return super.mark(element);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isValid(@NotNull PsiNameIdentifierOwner element) {
|
public boolean isValid(@NotNull PsiNameIdentifierOwner element) {
|
||||||
return element.getNameIdentifier() != null && super.isValid(element);
|
return (element.getNameIdentifier() != null || element instanceof JetObjectDeclaration) && super.isValid(element);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -174,7 +174,11 @@ public class OverrideResolver {
|
|||||||
OverridingUtil.resolveUnknownVisibilityForMember(descriptor, new OverridingUtil.NotInferredVisibilitySink() {
|
OverridingUtil.resolveUnknownVisibilityForMember(descriptor, new OverridingUtil.NotInferredVisibilitySink() {
|
||||||
@Override
|
@Override
|
||||||
public void cannotInferVisibility(@NotNull CallableMemberDescriptor descriptor) {
|
public void cannotInferVisibility(@NotNull CallableMemberDescriptor descriptor) {
|
||||||
PsiElement element = BindingContextUtils.descriptorToDeclaration(trace.getBindingContext(), descriptor);
|
DeclarationDescriptor reportOn = descriptor.getKind() == FAKE_OVERRIDE
|
||||||
|
? DescriptorUtils.getParentOfType(descriptor, ClassDescriptor.class)
|
||||||
|
: descriptor;
|
||||||
|
//noinspection ConstantConditions
|
||||||
|
PsiElement element = BindingContextUtils.descriptorToDeclaration(trace.getBindingContext(), reportOn);
|
||||||
if (element instanceof JetDeclaration) {
|
if (element instanceof JetDeclaration) {
|
||||||
trace.report(CANNOT_INFER_VISIBILITY.on((JetDeclaration) element));
|
trace.report(CANNOT_INFER_VISIBILITY.on((JetDeclaration) element));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
trait T {
|
||||||
|
internal fun foo()
|
||||||
|
}
|
||||||
|
|
||||||
|
open class C {
|
||||||
|
protected fun foo() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
class <!CANNOT_INFER_VISIBILITY!>E<!> : C(), T
|
||||||
|
|
||||||
|
val z: T = <!CANNOT_INFER_VISIBILITY!>object<!> : C(), T {}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
trait A {
|
||||||
|
internal fun foo()
|
||||||
|
}
|
||||||
|
|
||||||
|
trait B {
|
||||||
|
protected fun foo() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
class C {
|
||||||
|
class <!CANNOT_INFER_VISIBILITY!>object<!> : A, B {
|
||||||
|
fun bar() = null
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5384,6 +5384,16 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
|||||||
doTest("compiler/testData/diagnostics/tests/override/kt2052.kt");
|
doTest("compiler/testData/diagnostics/tests/override/kt2052.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt4785.kt")
|
||||||
|
public void testKt4785() throws Exception {
|
||||||
|
doTest("compiler/testData/diagnostics/tests/override/kt4785.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt4785classObject.kt")
|
||||||
|
public void testKt4785classObject() throws Exception {
|
||||||
|
doTest("compiler/testData/diagnostics/tests/override/kt4785classObject.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt880.kt")
|
@TestMetadata("kt880.kt")
|
||||||
public void testKt880() throws Exception {
|
public void testKt880() throws Exception {
|
||||||
doTest("compiler/testData/diagnostics/tests/override/kt880.kt");
|
doTest("compiler/testData/diagnostics/tests/override/kt880.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user