Fix "Cannot infer visibility" for fake overrides

#KT-4785 Fixed
This commit is contained in:
Alexander Udalov
2014-03-31 22:49:27 +04:00
parent 55b28fcd0e
commit 5ae339d940
5 changed files with 51 additions and 7 deletions
@@ -145,24 +145,30 @@ public class PositioningStrategies {
property.getTextRange().getStartOffset(), endOfSignatureElement.getTextRange().getEndOffset()));
}
else if (element instanceof JetClass) {
// primary constructor
JetClass klass = (JetClass)element;
PsiElement nameAsDeclaration = klass.getNameIdentifier();
PsiElement nameAsDeclaration = element.getNameIdentifier();
if (nameAsDeclaration == null) {
return markElement(klass);
return markElement(element);
}
PsiElement primaryConstructorParameterList = klass.getPrimaryConstructorParameterList();
PsiElement primaryConstructorParameterList = ((JetClass) element).getPrimaryConstructorParameterList();
if (primaryConstructorParameterList == null) {
return markRange(nameAsDeclaration.getTextRange());
}
return markRange(new TextRange(
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);
}
@Override
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() {
@Override
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) {
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");
}
@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")
public void testKt880() throws Exception {
doTest("compiler/testData/diagnostics/tests/override/kt880.kt");