added classes visibility check

This commit is contained in:
Svetlana Isakova
2012-04-02 15:37:02 +04:00
parent e364fe4259
commit 4d37672809
3 changed files with 20 additions and 5 deletions
@@ -56,6 +56,7 @@ public interface Errors {
});
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 NAME_SHADOWING = RedeclarationDiagnosticFactory.NAME_SHADOWING;
@@ -274,6 +274,11 @@ public class TypeResolver {
.lookupDescriptorsForUserType(userType, scope, trace);
for (DeclarationDescriptor descriptor : descriptors) {
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;
}
}
@@ -1,7 +1,7 @@
//FILE:a.kt
package a
private class A {
private open class A {
fun bar() {}
}
@@ -9,7 +9,10 @@ private fun foo() {}
fun makeA() = A()
private object PO {}
//FILE:b.kt
//+JDK
package a.b
import a.*
@@ -18,14 +21,20 @@ fun test() {
val y = makeA()
y.<!UNRESOLVED_REFERENCE!>bar<!>()
<!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 {
class B : <!INVISIBLE_MEMBER!>A<!>() {}
class Q {
class W {
fun foo() {
val y = makeA() //assure that 'makeA' is visible
val <!UNUSED_VARIABLE!>y<!> = makeA() //assure that 'makeA' is visible
}
}
}