added classes visibility check
This commit is contained in:
@@ -56,6 +56,7 @@ public interface Errors {
|
|||||||
});
|
});
|
||||||
|
|
||||||
UnresolvedReferenceDiagnosticFactory UNRESOLVED_REFERENCE = UnresolvedReferenceDiagnosticFactory.create("Unresolved reference");
|
UnresolvedReferenceDiagnosticFactory UNRESOLVED_REFERENCE = UnresolvedReferenceDiagnosticFactory.create("Unresolved reference");
|
||||||
|
DiagnosticFactory2<JetSimpleNameExpression, DeclarationDescriptor, DeclarationDescriptor> INVISIBLE_MEMBER = DiagnosticFactory2.create(ERROR, "''{0}'' has private access in ''{1}''", NAME, NAME);
|
||||||
|
|
||||||
RedeclarationDiagnosticFactory REDECLARATION = RedeclarationDiagnosticFactory.REDECLARATION;
|
RedeclarationDiagnosticFactory REDECLARATION = RedeclarationDiagnosticFactory.REDECLARATION;
|
||||||
RedeclarationDiagnosticFactory NAME_SHADOWING = RedeclarationDiagnosticFactory.NAME_SHADOWING;
|
RedeclarationDiagnosticFactory NAME_SHADOWING = RedeclarationDiagnosticFactory.NAME_SHADOWING;
|
||||||
|
|||||||
@@ -274,6 +274,11 @@ public class TypeResolver {
|
|||||||
.lookupDescriptorsForUserType(userType, scope, trace);
|
.lookupDescriptorsForUserType(userType, scope, trace);
|
||||||
for (DeclarationDescriptor descriptor : descriptors) {
|
for (DeclarationDescriptor descriptor : descriptors) {
|
||||||
if (descriptor instanceof ClassifierDescriptor) {
|
if (descriptor instanceof ClassifierDescriptor) {
|
||||||
|
if (descriptor instanceof ClassDescriptor && !Visibilities.isVisible((ClassDescriptor)descriptor, scope.getContainingDeclaration())) {
|
||||||
|
JetSimpleNameExpression referenceExpression = userType.getReferenceExpression();
|
||||||
|
assert referenceExpression != null;
|
||||||
|
trace.report(INVISIBLE_MEMBER.on(referenceExpression, descriptor, ((ClassDescriptor)descriptor).getContainingDeclaration()));
|
||||||
|
}
|
||||||
return (ClassifierDescriptor) descriptor;
|
return (ClassifierDescriptor) descriptor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
//FILE:a.kt
|
//FILE:a.kt
|
||||||
package a
|
package a
|
||||||
|
|
||||||
private class A {
|
private open class A {
|
||||||
fun bar() {}
|
fun bar() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -9,7 +9,10 @@ private fun foo() {}
|
|||||||
|
|
||||||
fun makeA() = A()
|
fun makeA() = A()
|
||||||
|
|
||||||
|
private object PO {}
|
||||||
|
|
||||||
//FILE:b.kt
|
//FILE:b.kt
|
||||||
|
//+JDK
|
||||||
package a.b
|
package a.b
|
||||||
|
|
||||||
import a.*
|
import a.*
|
||||||
@@ -18,14 +21,20 @@ fun test() {
|
|||||||
val y = makeA()
|
val y = makeA()
|
||||||
y.<!UNRESOLVED_REFERENCE!>bar<!>()
|
y.<!UNRESOLVED_REFERENCE!>bar<!>()
|
||||||
<!UNRESOLVED_REFERENCE!>foo<!>()
|
<!UNRESOLVED_REFERENCE!>foo<!>()
|
||||||
|
|
||||||
|
val <!UNUSED_VARIABLE!>u<!> : <!INVISIBLE_MEMBER!>A<!> = <!UNRESOLVED_REFERENCE!>A<!>()
|
||||||
|
val <!UNUSED_VARIABLE!>a<!> : java.util.Arrays.<!INVISIBLE_MEMBER!>ArrayList<!><Int>;
|
||||||
|
|
||||||
|
val <!UNUSED_VARIABLE!>po<!> = <!UNRESOLVED_REFERENCE!>PO<!>()
|
||||||
}
|
}
|
||||||
|
|
||||||
class A {
|
class B : <!INVISIBLE_MEMBER!>A<!>() {}
|
||||||
class B {
|
|
||||||
|
class Q {
|
||||||
|
class W {
|
||||||
fun foo() {
|
fun foo() {
|
||||||
val y = makeA() //assure that 'makeA' is visible
|
val <!UNUSED_VARIABLE!>y<!> = makeA() //assure that 'makeA' is visible
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user