From f9afdf7540e304e3bf118b8086fe4177157df5c6 Mon Sep 17 00:00:00 2001 From: Stanislav Erokhin Date: Thu, 16 Oct 2014 16:30:13 +0400 Subject: [PATCH] Use Visibilities.isVisible with ReceiverValue. --- .../lang/cfg/JetFlowInformationProvider.java | 13 ++++++- .../jet/lang/resolve/OverrideResolver.java | 3 +- .../resolve/QualifiedExpressionResolver.java | 3 +- .../lang/resolve/calls/CandidateResolver.java | 3 +- .../resolve/calls/tasks/TaskPrioritizer.kt | 3 +- .../expressions/ExpressionTypingUtils.java | 23 +++++++++++ .../variance/privateToThis/FunctionCall.kt | 39 +++++++++++++++++++ .../variance/privateToThis/FunctionCall.txt | 24 ++++++++++++ .../tests/variance/privateToThis/GetVal.kt | 38 ++++++++++++++++++ .../tests/variance/privateToThis/GetVal.txt | 24 ++++++++++++ .../tests/variance/privateToThis/SetVar.kt | 38 ++++++++++++++++++ .../tests/variance/privateToThis/SetVar.txt | 24 ++++++++++++ .../variance/privateToThis/ValReassigned.kt | 20 ++++++++++ .../variance/privateToThis/ValReassigned.txt | 14 +++++++ .../checkers/JetDiagnosticsTestGenerated.java | 34 ++++++++++++++++ .../jet/lang/descriptors/Visibilities.java | 4 -- .../jet/lang/resolve/OverridingUtil.java | 6 ++- .../jet/plugin/completion/ExpectedInfos.kt | 5 ++- 18 files changed, 305 insertions(+), 13 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/variance/privateToThis/FunctionCall.kt create mode 100644 compiler/testData/diagnostics/tests/variance/privateToThis/FunctionCall.txt create mode 100644 compiler/testData/diagnostics/tests/variance/privateToThis/GetVal.kt create mode 100644 compiler/testData/diagnostics/tests/variance/privateToThis/GetVal.txt create mode 100644 compiler/testData/diagnostics/tests/variance/privateToThis/SetVar.kt create mode 100644 compiler/testData/diagnostics/tests/variance/privateToThis/SetVar.txt create mode 100644 compiler/testData/diagnostics/tests/variance/privateToThis/ValReassigned.kt create mode 100644 compiler/testData/diagnostics/tests/variance/privateToThis/ValReassigned.txt diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetFlowInformationProvider.java b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetFlowInformationProvider.java index e3480eae989..0c3f373b3ed 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetFlowInformationProvider.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetFlowInformationProvider.java @@ -53,6 +53,7 @@ import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.resolve.*; import org.jetbrains.jet.lang.resolve.bindingContextUtil.BindingContextUtilPackage; import org.jetbrains.jet.lang.resolve.calls.TailRecursionKind; +import org.jetbrains.jet.lang.resolve.calls.callUtil.CallUtilPackage; import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall; import org.jetbrains.jet.lang.resolve.scopes.receivers.ExpressionReceiver; import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue; @@ -414,8 +415,16 @@ public class JetFlowInformationProvider { if (variableDescriptor.isVar() && variableDescriptor instanceof PropertyDescriptor) { DeclarationDescriptor descriptor = BindingContextUtils.getEnclosingDescriptor(trace.getBindingContext(), expression); PropertySetterDescriptor setterDescriptor = ((PropertyDescriptor) variableDescriptor).getSetter(); - if (Visibilities.isVisible(variableDescriptor, descriptor) && setterDescriptor != null - && !Visibilities.isVisible(setterDescriptor, descriptor)) { + + ResolvedCall resolvedCall = CallUtilPackage.getResolvedCall(expression, trace.getBindingContext()); + ReceiverValue receiverValue = ReceiverValue.IRRELEVANT_RECEIVER; + if (resolvedCall != null) { + receiverValue = ExpressionTypingUtils + .normalizeReceiverValueForVisibility(resolvedCall.getDispatchReceiver(), trace.getBindingContext()); + + } + if (Visibilities.isVisible(receiverValue, variableDescriptor, descriptor) && setterDescriptor != null + && !Visibilities.isVisible(receiverValue, setterDescriptor, descriptor)) { report(Errors.INVISIBLE_SETTER.on(expression, variableDescriptor, setterDescriptor.getVisibility(), variableDescriptor.getContainingDeclaration()), ctxt); return true; diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/OverrideResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/OverrideResolver.java index 768e01cdde2..1197745de64 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/OverrideResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/OverrideResolver.java @@ -37,6 +37,7 @@ import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.resolve.calls.CallResolverUtil; import org.jetbrains.jet.lang.resolve.dataClassUtils.DataClassUtilsPackage; import org.jetbrains.jet.lang.resolve.name.Name; +import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue; import org.jetbrains.jet.lang.types.*; import org.jetbrains.jet.lang.types.checker.JetTypeChecker; import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns; @@ -821,7 +822,7 @@ public class OverrideResolver { all.addAll((Collection) supertype.getMemberScope().getProperties(declared.getName())); for (CallableMemberDescriptor fromSuper : all) { if (OverridingUtil.DEFAULT.isOverridableBy(fromSuper, declared).getResult() == OVERRIDABLE) { - if (Visibilities.isVisible(fromSuper, declared)) { + if (Visibilities.isVisible(ReceiverValue.IRRELEVANT_RECEIVER, fromSuper, declared)) { throw new IllegalStateException("Descriptor " + fromSuper + " is overridable by " + declared + " and visible but does not appear in its getOverriddenDescriptors()"); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/QualifiedExpressionResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/QualifiedExpressionResolver.java index 932d7b3e5ab..742e62656d2 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/QualifiedExpressionResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/QualifiedExpressionResolver.java @@ -28,6 +28,7 @@ import org.jetbrains.jet.lang.diagnostics.Errors; import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.resolve.name.Name; import org.jetbrains.jet.lang.resolve.scopes.JetScope; +import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue; import java.util.Collection; import java.util.Collections; @@ -457,7 +458,7 @@ public class QualifiedExpressionResolver { @NotNull JetSimpleNameExpression referenceExpression, @NotNull JetScope scopeToCheckVisibility ) { - if (!Visibilities.isVisible(descriptor, scopeToCheckVisibility.getContainingDeclaration())) { + if (!Visibilities.isVisible(ReceiverValue.IRRELEVANT_RECEIVER, descriptor, scopeToCheckVisibility.getContainingDeclaration())) { //noinspection ConstantConditions trace.report(INVISIBLE_REFERENCE.on(referenceExpression, descriptor, descriptor.getVisibility(), descriptor.getContainingDeclaration())); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CandidateResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CandidateResolver.java index ffc252f4f69..4583371bc18 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CandidateResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CandidateResolver.java @@ -91,8 +91,9 @@ public class CandidateResolver { } + ReceiverValue receiverValue = ExpressionTypingUtils.normalizeReceiverValueForVisibility(candidateCall.getDispatchReceiver(), context.trace.getBindingContext()); DeclarationDescriptorWithVisibility invisibleMember = - Visibilities.findInvisibleMember(ReceiverValue.IRRELEVANT_RECEIVER, candidate, context.scope.getContainingDeclaration()); + Visibilities.findInvisibleMember(receiverValue, candidate, context.scope.getContainingDeclaration()); if (invisibleMember != null) { candidateCall.addStatus(OTHER_ERROR); context.tracing.invisibleMember(context.trace, invisibleMember); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/tasks/TaskPrioritizer.kt b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/tasks/TaskPrioritizer.kt index c769d557767..c838ae45d17 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/tasks/TaskPrioritizer.kt +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/tasks/TaskPrioritizer.kt @@ -413,7 +413,8 @@ public class TaskPrioritizer(private val storageManager: StorageManager) { if (call == null) return false val candidateDescriptor = call.getDescriptor() if (ErrorUtils.isError(candidateDescriptor)) return true - return Visibilities.isVisible(candidateDescriptor, context.scope.getContainingDeclaration()) + val receiverValue = ExpressionTypingUtils.normalizeReceiverValueForVisibility(call.getDispatchReceiver(), context.trace.getBindingContext()) + return Visibilities.isVisible(receiverValue, candidateDescriptor, context.scope.getContainingDeclaration()) } private fun isSynthesized(call: ResolutionCandidate): Boolean { diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ExpressionTypingUtils.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ExpressionTypingUtils.java index 08a6bf4f35e..423d2d71a83 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ExpressionTypingUtils.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ExpressionTypingUtils.java @@ -41,6 +41,7 @@ import org.jetbrains.jet.lang.resolve.name.Name; import org.jetbrains.jet.lang.resolve.scopes.JetScope; import org.jetbrains.jet.lang.resolve.scopes.WritableScope; import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl; +import org.jetbrains.jet.lang.resolve.scopes.receivers.ClassReceiver; import org.jetbrains.jet.lang.resolve.scopes.receivers.ExpressionReceiver; import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue; import org.jetbrains.jet.lang.types.ErrorUtils; @@ -77,6 +78,28 @@ public class ExpressionTypingUtils { this.builtIns = builtIns; } + @NotNull + public static ReceiverValue normalizeReceiverValueForVisibility(@NotNull ReceiverValue receiverValue, @NotNull BindingContext trace) { + if (receiverValue instanceof ExpressionReceiver) { + JetExpression expression = ((ExpressionReceiver) receiverValue).getExpression(); + JetReferenceExpression referenceExpression = null; + if (expression instanceof JetThisExpression) { + referenceExpression = ((JetThisExpression) expression).getInstanceReference(); + } + else if (expression instanceof JetThisReferenceExpression) { + referenceExpression = (JetReferenceExpression) expression; + } + + if (referenceExpression != null) { + DeclarationDescriptor descriptor = trace.get(BindingContext.REFERENCE_TARGET, referenceExpression); + if (descriptor instanceof ClassDescriptor) { + return new ClassReceiver((ClassDescriptor) descriptor.getOriginal()); + } + } + } + return receiverValue; + } + @Nullable protected static ExpressionReceiver getExpressionReceiver(@NotNull JetExpression expression, @Nullable JetType type) { if (type == null) return null; diff --git a/compiler/testData/diagnostics/tests/variance/privateToThis/FunctionCall.kt b/compiler/testData/diagnostics/tests/variance/privateToThis/FunctionCall.kt new file mode 100644 index 00000000000..1a30d20685b --- /dev/null +++ b/compiler/testData/diagnostics/tests/variance/privateToThis/FunctionCall.kt @@ -0,0 +1,39 @@ +fun getT(): T = null!! +fun with(receiver: T, f: T.() -> R): R = receiver.f() + + +class Test { + private fun foo() : I = getT() + + fun apply(i: I) {} + + { + foo() + this.foo() + } + + fun test() { + apply(foo()) + apply(this.foo()) + with(Test()) { + apply(foo()) // resolved to this@Test.foo + apply(this.foo()) + apply(this@with.foo()) + apply(this@Test.foo()) + } + } + + fun test(t: Test) { + t.apply(t.foo()) + } + + class object { + fun test(t: Test) { + t.apply(t.foo()) + } + } +} + +fun test(t: Test) { + t.apply(t.foo()) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/variance/privateToThis/FunctionCall.txt b/compiler/testData/diagnostics/tests/variance/privateToThis/FunctionCall.txt new file mode 100644 index 00000000000..bdbea61466c --- /dev/null +++ b/compiler/testData/diagnostics/tests/variance/privateToThis/FunctionCall.txt @@ -0,0 +1,24 @@ +package + +internal fun getT(): T +internal fun test(/*0*/ t: Test): kotlin.Unit +internal fun with(/*0*/ receiver: T, /*1*/ f: T.() -> R): R + +internal final class Test { + public constructor Test() + internal final fun apply(/*0*/ i: I): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + private/*private to this*/ final fun foo(): I + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + internal final fun test(): kotlin.Unit + internal final fun test(/*0*/ t: Test): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + internal class object { + private constructor () + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + internal final fun test(/*0*/ t: Test): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } +} diff --git a/compiler/testData/diagnostics/tests/variance/privateToThis/GetVal.kt b/compiler/testData/diagnostics/tests/variance/privateToThis/GetVal.kt new file mode 100644 index 00000000000..71f5b542e8c --- /dev/null +++ b/compiler/testData/diagnostics/tests/variance/privateToThis/GetVal.kt @@ -0,0 +1,38 @@ +fun getT(): T = null!! +fun with(receiver: T, f: T.() -> R): R = receiver.f() + +class Test { + private val i: I = getT() + + ;{ + apply(i) + apply(this.i) + } + + fun apply(i: I) {} + + fun test() { + apply(i) + apply(this.i) + with(Test()) { + apply(i) // resolved to this@Test.i + apply(this.i) + apply(this@with.i) + apply(this@Test.i) + } + } + + fun test(t: Test) { + t.apply(t.i) + } + + class object { + fun test(t: Test) { + t.apply(t.i) + } + } +} + +fun test(t: Test) { + t.apply(t.i) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/variance/privateToThis/GetVal.txt b/compiler/testData/diagnostics/tests/variance/privateToThis/GetVal.txt new file mode 100644 index 00000000000..77fcbad6e04 --- /dev/null +++ b/compiler/testData/diagnostics/tests/variance/privateToThis/GetVal.txt @@ -0,0 +1,24 @@ +package + +internal fun getT(): T +internal fun test(/*0*/ t: Test): kotlin.Unit +internal fun with(/*0*/ receiver: T, /*1*/ f: T.() -> R): R + +internal final class Test { + public constructor Test() + private/*private to this*/ final val i: I + internal final fun apply(/*0*/ i: I): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + internal final fun test(): kotlin.Unit + internal final fun test(/*0*/ t: Test): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + internal class object { + private constructor () + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + internal final fun test(/*0*/ t: Test): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } +} diff --git a/compiler/testData/diagnostics/tests/variance/privateToThis/SetVar.kt b/compiler/testData/diagnostics/tests/variance/privateToThis/SetVar.kt new file mode 100644 index 00000000000..7fbfbf8f1d0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/variance/privateToThis/SetVar.kt @@ -0,0 +1,38 @@ +fun getT(): T = null!! +fun with(receiver: T, f: T.() -> R): R = receiver.f() + +class Test { + private var i: I = getT() + private val j: I + + ;{ + j = getT() + i = getT() + this.i = getT() + } + + fun test() { + i = getT() + this.i = getT() + with(Test()) { + i = getT() // resolved to this@Test.i + this.i = getT() + this@with.i = getT() + this@Test.i = getT() + } + } + + fun test(t: Test) { + t.i = getT() + } + + class object { + fun test(t: Test) { + t.i = getT() + } + } +} + +fun test(t: Test) { + t.i = getT() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/variance/privateToThis/SetVar.txt b/compiler/testData/diagnostics/tests/variance/privateToThis/SetVar.txt new file mode 100644 index 00000000000..9f4b2dc533e --- /dev/null +++ b/compiler/testData/diagnostics/tests/variance/privateToThis/SetVar.txt @@ -0,0 +1,24 @@ +package + +internal fun getT(): T +internal fun test(/*0*/ t: Test): kotlin.Unit +internal fun with(/*0*/ receiver: T, /*1*/ f: T.() -> R): R + +internal final class Test { + public constructor Test() + private/*private to this*/ final var i: I + private/*private to this*/ final val j: I + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + internal final fun test(): kotlin.Unit + internal final fun test(/*0*/ t: Test): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + internal class object { + private constructor () + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + internal final fun test(/*0*/ t: Test): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } +} diff --git a/compiler/testData/diagnostics/tests/variance/privateToThis/ValReassigned.kt b/compiler/testData/diagnostics/tests/variance/privateToThis/ValReassigned.kt new file mode 100644 index 00000000000..10c869b1db7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/variance/privateToThis/ValReassigned.kt @@ -0,0 +1,20 @@ +fun getT(): T = null!! + +class A(init: I) { + private val i: I + + { + i = getT() + } + + private var i2 = i + private val i3: I + + private var i4 = getT() + + ;{ + i2 = getT() + i3 = init + i4 = i3 + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/variance/privateToThis/ValReassigned.txt b/compiler/testData/diagnostics/tests/variance/privateToThis/ValReassigned.txt new file mode 100644 index 00000000000..d9dbb609ddb --- /dev/null +++ b/compiler/testData/diagnostics/tests/variance/privateToThis/ValReassigned.txt @@ -0,0 +1,14 @@ +package + +internal fun getT(): T + +internal final class A { + public constructor A(/*0*/ init: I) + private/*private to this*/ final val i: I + private/*private to this*/ final var i2: I + private/*private to this*/ final val i3: I + private/*private to this*/ final var i4: I + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java index 4a048efc084..7e7523264f9 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java @@ -10286,6 +10286,7 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest { @TestMetadata("compiler/testData/diagnostics/tests/variance") @TestDataPath("$PROJECT_ROOT") + @InnerTestClasses({Variance.PrivateToThis.class}) @RunWith(JUnit3RunnerWithInners.class) public static class Variance extends AbstractJetDiagnosticsTest { public void testAllFilesPresentInVariance() throws Exception { @@ -10357,6 +10358,39 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest { String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/variance/Visibility.kt"); doTest(fileName); } + + @TestMetadata("compiler/testData/diagnostics/tests/variance/privateToThis") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class PrivateToThis extends AbstractJetDiagnosticsTest { + public void testAllFilesPresentInPrivateToThis() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/tests/variance/privateToThis"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("FunctionCall.kt") + public void testFunctionCall() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/variance/privateToThis/FunctionCall.kt"); + doTest(fileName); + } + + @TestMetadata("GetVal.kt") + public void testGetVal() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/variance/privateToThis/GetVal.kt"); + doTest(fileName); + } + + @TestMetadata("SetVar.kt") + public void testSetVar() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/variance/privateToThis/SetVar.kt"); + doTest(fileName); + } + + @TestMetadata("ValReassigned.kt") + public void testValReassigned() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/variance/privateToThis/ValReassigned.kt"); + doTest(fileName); + } + } } @TestMetadata("compiler/testData/diagnostics/tests/when") diff --git a/core/descriptors/src/org/jetbrains/jet/lang/descriptors/Visibilities.java b/core/descriptors/src/org/jetbrains/jet/lang/descriptors/Visibilities.java index ff7e73f4b2c..1d060aa4942 100644 --- a/core/descriptors/src/org/jetbrains/jet/lang/descriptors/Visibilities.java +++ b/core/descriptors/src/org/jetbrains/jet/lang/descriptors/Visibilities.java @@ -139,10 +139,6 @@ public class Visibilities { private Visibilities() { } - public static boolean isVisible(@NotNull DeclarationDescriptorWithVisibility what, @NotNull DeclarationDescriptor from) { - return isVisible(ReceiverValue.IRRELEVANT_RECEIVER, what, from); - } - public static boolean isVisible(@NotNull ReceiverValue receiver, @NotNull DeclarationDescriptorWithVisibility what, @NotNull DeclarationDescriptor from) { return findInvisibleMember(receiver, what, from) == null; } diff --git a/core/descriptors/src/org/jetbrains/jet/lang/resolve/OverridingUtil.java b/core/descriptors/src/org/jetbrains/jet/lang/resolve/OverridingUtil.java index e35e128774a..6fc14a9c3f7 100644 --- a/core/descriptors/src/org/jetbrains/jet/lang/resolve/OverridingUtil.java +++ b/core/descriptors/src/org/jetbrains/jet/lang/resolve/OverridingUtil.java @@ -27,6 +27,7 @@ import org.jetbrains.jet.lang.descriptors.impl.FunctionDescriptorImpl; import org.jetbrains.jet.lang.descriptors.impl.PropertyAccessorDescriptorImpl; import org.jetbrains.jet.lang.descriptors.impl.PropertyDescriptorImpl; import org.jetbrains.jet.lang.resolve.name.Name; +import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue; import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lang.types.TypeConstructor; import org.jetbrains.jet.lang.types.checker.JetTypeChecker; @@ -269,7 +270,7 @@ public class OverridingUtil { for (CallableMemberDescriptor fromSupertype : descriptorsFromSuper) { OverrideCompatibilityInfo.Result result = DEFAULT.isOverridableBy(fromSupertype, fromCurrent).getResult(); - boolean isVisible = Visibilities.isVisible(fromSupertype, current); + boolean isVisible = Visibilities.isVisible(ReceiverValue.IRRELEVANT_RECEIVER, fromSupertype, current); switch (result) { case OVERRIDABLE: if (isVisible) { @@ -378,7 +379,8 @@ public class OverridingUtil { @Override public Boolean invoke(CallableMemberDescriptor descriptor) { //nested class could capture private member, so check for private visibility added - return !Visibilities.isPrivate(descriptor.getVisibility()) && Visibilities.isVisible(descriptor, current); + return !Visibilities.isPrivate(descriptor.getVisibility()) && + Visibilities.isVisible(ReceiverValue.IRRELEVANT_RECEIVER, descriptor, current); } }); } diff --git a/idea/src/org/jetbrains/jet/plugin/completion/ExpectedInfos.kt b/idea/src/org/jetbrains/jet/plugin/completion/ExpectedInfos.kt index 301717c1b4b..07a194b0441 100644 --- a/idea/src/org/jetbrains/jet/plugin/completion/ExpectedInfos.kt +++ b/idea/src/org/jetbrains/jet/plugin/completion/ExpectedInfos.kt @@ -68,6 +68,7 @@ import org.jetbrains.jet.lang.descriptors.VariableDescriptor import org.jetbrains.jet.lang.resolve.calls.results.ResolutionStatus import org.jetbrains.jet.plugin.caches.resolve.ResolutionFacade import org.jetbrains.jet.lang.types.typeUtil.isSubtypeOf +import org.jetbrains.jet.lang.types.expressions.ExpressionTypingUtils enum class Tail { COMMA @@ -186,7 +187,9 @@ class ExpectedInfos(val bindingContext: BindingContext, val resolutionFacade: Re // consider only candidates with more arguments than in the truncated call and with all arguments before the current one matched if (candidate.noErrorsInValueArguments() && (candidate.getCandidateDescriptor().getValueParameters().size > argumentIndex || isFunctionLiteralArgument)) { val descriptor = candidate.getResultingDescriptor() - if (!Visibilities.isVisible(descriptor, resolutionScope.getContainingDeclaration())) continue + + val thisReceiver = ExpressionTypingUtils.normalizeReceiverValueForVisibility(candidate.getDispatchReceiver(), bindingContext) + if (!Visibilities.isVisible(thisReceiver, descriptor, resolutionScope.getContainingDeclaration())) continue val parameters = descriptor.getValueParameters() if (isFunctionLiteralArgument && argumentIndex != parameters.lastIndex) continue