Overriden setter now cannot weaken visibility #KT-3369 Fixed

This commit is contained in:
Mikhail Glukhikh
2015-11-13 18:33:58 +03:00
parent 02fb19c3ea
commit 86c37deaee
4 changed files with 69 additions and 0 deletions
@@ -917,6 +917,13 @@ public class OverrideResolver {
private void checkVisibility(@NotNull TopDownAnalysisContext c) {
for (Map.Entry<KtCallableDeclaration, CallableMemberDescriptor> entry : c.getMembers().entrySet()) {
checkVisibilityForMember(entry.getKey(), entry.getValue());
if (entry.getKey() instanceof KtProperty && entry.getValue() instanceof PropertyDescriptor) {
KtPropertyAccessor setter = ((KtProperty) entry.getKey()).getSetter();
PropertySetterDescriptor setterDescriptor = ((PropertyDescriptor) entry.getValue()).getSetter();
if (setter != null && setterDescriptor != null) {
checkVisibilityForMember(setter, setterDescriptor);
}
}
}
}
@@ -0,0 +1,29 @@
public interface ITest {
public var prop : Int
get() = 12
set(value) {}
}
abstract class ATest {
protected open var prop2 : Int
get() = 13
set(value) {}
}
class Test: ATest(), ITest {
override var prop : Int
get() = 12
<!CANNOT_WEAKEN_ACCESS_PRIVILEGE!>private<!> set(value) {}
override var prop2 : Int
get() = 14
<!CANNOT_CHANGE_ACCESS_PRIVILEGE!>internal<!> set(value) {}
}
fun main(args: Array<String>) {
val test = Test()
<!INVISIBLE_SETTER!>test.prop<!> = 12
val itest: ITest = test
itest.prop = 12 // No error here
}
@@ -0,0 +1,27 @@
package
public fun main(/*0*/ args: kotlin.Array<kotlin.String>): kotlin.Unit
public abstract class ATest {
public constructor ATest()
protected open var prop2: kotlin.Int
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
}
public interface ITest {
public open var prop: kotlin.Int
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
}
public final class Test : ATest, ITest {
public constructor Test()
public open override /*1*/ var prop: kotlin.Int
protected open override /*1*/ var prop2: kotlin.Int
public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -433,6 +433,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
doTest(fileName);
}
@TestMetadata("OverridenSetterVisibility.kt")
public void testOverridenSetterVisibility() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/OverridenSetterVisibility.kt");
doTest(fileName);
}
@TestMetadata("OverridingVarByVal.kt")
public void testOverridingVarByVal() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/OverridingVarByVal.kt");