FIR: Handle visibility of public setter of protected synthetic property like in K1

K1 allows writing access to a public setter of a protected synthetic
property only if the call is inside a subclass. K2 previously allowed
that unconditionally. This changes brings the behavior in line with K1.

^KT-56050 Fixed
This commit is contained in:
Kirill Rakhman
2023-01-24 15:38:52 +01:00
committed by Space Team
parent 1990883bdc
commit f6c189be7b
5 changed files with 254 additions and 18 deletions
@@ -1,9 +1,9 @@
// FILE: j/Super.java
package j
public abstract class Super {
protected abstract String getName();
public abstract void setName(String s);
public class Super {
protected String getName() { return "" };
public void setName(String s) { }
}
// FILE: k/test.kt
@@ -11,20 +11,110 @@ public abstract class Super {
package k
import j.Super
abstract class Sub: Super() {
abstract class Sub : Super() {
fun test(s: Super) {
s.<!INVISIBLE_REFERENCE!>name<!>
s.<!INVISIBLE_REFERENCE!>getName<!>()
s.name = ""
s.name = s.<!INVISIBLE_REFERENCE!>name<!>
s.setName("")
val anon1 = object : Super() {
fun testAnon() {
s.<!INVISIBLE_REFERENCE!>name<!>
s.<!INVISIBLE_REFERENCE!>getName<!>()
s.name = ""
s.name = s.<!INVISIBLE_REFERENCE!>name<!>
s.setName("")
}
}
val anon2 = object {
fun testAnon() {
s.<!INVISIBLE_REFERENCE!>name<!>
s.<!INVISIBLE_REFERENCE!>getName<!>()
s.name = ""
s.name = s.<!INVISIBLE_REFERENCE!>name<!>
s.setName("")
}
}
}
inner class Nested1 : Super() {
fun test(s: Super) {
s.<!INVISIBLE_REFERENCE!>name<!>
s.<!INVISIBLE_REFERENCE!>getName<!>()
s.name = ""
s.name = s.<!INVISIBLE_REFERENCE!>name<!>
s.setName("")
}
}
class Nested2 {
fun test(s: Super) {
s.<!INVISIBLE_REFERENCE!>name<!>
s.<!INVISIBLE_REFERENCE!>getName<!>()
s.name = ""
s.name = s.<!INVISIBLE_REFERENCE!>name<!>
s.setName("")
}
}
}
abstract class NonSub {
fun test(s: Super) {
s.<!INVISIBLE_REFERENCE!>name<!>
s.<!INVISIBLE_REFERENCE!>getName<!>()
s.<!INVISIBLE_REFERENCE!>name<!> = ""
s.<!INVISIBLE_REFERENCE!>name<!> = s.<!INVISIBLE_REFERENCE!>name<!>
s.setName("")
val anon1 = object : Super() {
fun testAnon() {
s.<!INVISIBLE_REFERENCE!>name<!>
s.<!INVISIBLE_REFERENCE!>getName<!>()
s.name = ""
s.name = s.<!INVISIBLE_REFERENCE!>name<!>
s.setName("")
}
}
val anon2 = object {
fun testAnon() {
s.<!INVISIBLE_REFERENCE!>name<!>
s.<!INVISIBLE_REFERENCE!>getName<!>()
s.<!INVISIBLE_REFERENCE!>name<!> = ""
s.<!INVISIBLE_REFERENCE!>name<!> = s.<!INVISIBLE_REFERENCE!>name<!>
s.setName("")
}
}
}
inner class Nested1 : Super() {
fun test(s: Super) {
s.<!INVISIBLE_REFERENCE!>name<!>
s.<!INVISIBLE_REFERENCE!>getName<!>()
s.name = ""
s.name = s.<!INVISIBLE_REFERENCE!>name<!>
s.setName("")
}
}
class Nested2 {
fun test(s: Super) {
s.<!INVISIBLE_REFERENCE!>name<!>
s.<!INVISIBLE_REFERENCE!>getName<!>()
s.<!INVISIBLE_REFERENCE!>name<!> = ""
s.<!INVISIBLE_REFERENCE!>name<!> = s.<!INVISIBLE_REFERENCE!>name<!>
s.setName("")
}
}
}
fun test(s: Super) {
s.<!INVISIBLE_REFERENCE!>name<!>
s.<!INVISIBLE_REFERENCE!>getName<!>()
s.name = ""
s.name = s.<!INVISIBLE_REFERENCE!>name<!>
s.<!INVISIBLE_REFERENCE!>name<!> = ""
s.<!INVISIBLE_REFERENCE!>name<!> = s.<!INVISIBLE_REFERENCE!>name<!>
s.setName("")
}
@@ -1,9 +1,9 @@
// FILE: j/Super.java
package j
public abstract class Super {
protected abstract String getName();
public abstract void setName(String s);
public class Super {
protected String getName() { return "" };
public void setName(String s) { }
}
// FILE: k/test.kt
@@ -11,13 +11,103 @@ public abstract class Super {
package k
import j.Super
abstract class Sub: Super() {
abstract class Sub : Super() {
fun test(s: Super) {
s.<!INVISIBLE_MEMBER!>name<!>
s.<!INVISIBLE_MEMBER!>getName<!>()
s.name = ""
s.name = s.<!INVISIBLE_MEMBER!>name<!>
s.setName("")
val anon1 = object : Super() {
fun testAnon() {
s.<!INVISIBLE_MEMBER!>name<!>
s.<!INVISIBLE_MEMBER!>getName<!>()
s.name = ""
s.name = s.<!INVISIBLE_MEMBER!>name<!>
s.setName("")
}
}
val anon2 = object {
fun testAnon() {
s.<!INVISIBLE_MEMBER!>name<!>
s.<!INVISIBLE_MEMBER!>getName<!>()
s.name = ""
s.name = s.<!INVISIBLE_MEMBER!>name<!>
s.setName("")
}
}
}
inner class Nested1 : Super() {
fun test(s: Super) {
s.<!INVISIBLE_MEMBER!>name<!>
s.<!INVISIBLE_MEMBER!>getName<!>()
s.name = ""
s.name = s.<!INVISIBLE_MEMBER!>name<!>
s.setName("")
}
}
class Nested2 {
fun test(s: Super) {
s.<!INVISIBLE_MEMBER!>name<!>
s.<!INVISIBLE_MEMBER!>getName<!>()
s.name = ""
s.name = s.<!INVISIBLE_MEMBER!>name<!>
s.setName("")
}
}
}
abstract class NonSub {
fun test(s: Super) {
s.<!INVISIBLE_MEMBER!>name<!>
s.<!INVISIBLE_MEMBER!>getName<!>()
s.<!INVISIBLE_MEMBER!>name<!> = ""
s.<!INVISIBLE_MEMBER!>name<!> = s.<!INVISIBLE_MEMBER!>name<!>
s.setName("")
val anon1 = object : Super() {
fun testAnon() {
s.<!INVISIBLE_MEMBER!>name<!>
s.<!INVISIBLE_MEMBER!>getName<!>()
s.name = ""
s.name = s.<!INVISIBLE_MEMBER!>name<!>
s.setName("")
}
}
val anon2 = object {
fun testAnon() {
s.<!INVISIBLE_MEMBER!>name<!>
s.<!INVISIBLE_MEMBER!>getName<!>()
s.<!INVISIBLE_MEMBER!>name<!> = ""
s.<!INVISIBLE_MEMBER!>name<!> = s.<!INVISIBLE_MEMBER!>name<!>
s.setName("")
}
}
}
inner class Nested1 : Super() {
fun test(s: Super) {
s.<!INVISIBLE_MEMBER!>name<!>
s.<!INVISIBLE_MEMBER!>getName<!>()
s.name = ""
s.name = s.<!INVISIBLE_MEMBER!>name<!>
s.setName("")
}
}
class Nested2 {
fun test(s: Super) {
s.<!INVISIBLE_MEMBER!>name<!>
s.<!INVISIBLE_MEMBER!>getName<!>()
s.<!INVISIBLE_MEMBER!>name<!> = ""
s.<!INVISIBLE_MEMBER!>name<!> = s.<!INVISIBLE_MEMBER!>name<!>
s.setName("")
}
}
}
@@ -2,12 +2,12 @@ package
package j {
public abstract class Super {
public open class Super {
public constructor Super()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
protected/*protected and package*/ abstract fun getName(): kotlin.String!
protected/*protected and package*/ open fun getName(): kotlin.String!
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public abstract fun setName(/*0*/ s: kotlin.String!): kotlin.Unit
public open fun setName(/*0*/ s: kotlin.String!): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
}
@@ -15,13 +15,58 @@ package j {
package k {
public fun test(/*0*/ s: j.Super): kotlin.Unit
public abstract class NonSub {
public constructor NonSub()
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 final fun test(/*0*/ s: j.Super): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
public final inner class Nested1 : j.Super {
public constructor Nested1()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
protected/*protected and package*/ open override /*1*/ /*fake_override*/ fun getName(): kotlin.String!
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun setName(/*0*/ s: kotlin.String!): kotlin.Unit
public final fun test(/*0*/ s: j.Super): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class Nested2 {
public constructor Nested2()
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 final fun test(/*0*/ s: j.Super): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
}
public abstract class Sub : j.Super {
public constructor Sub()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
protected/*protected and package*/ abstract override /*1*/ /*fake_override*/ fun getName(): kotlin.String!
protected/*protected and package*/ open override /*1*/ /*fake_override*/ fun getName(): kotlin.String!
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public abstract override /*1*/ /*fake_override*/ fun setName(/*0*/ s: kotlin.String!): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun setName(/*0*/ s: kotlin.String!): kotlin.Unit
public final fun test(/*0*/ s: j.Super): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
public final inner class Nested1 : j.Super {
public constructor Nested1()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
protected/*protected and package*/ open override /*1*/ /*fake_override*/ fun getName(): kotlin.String!
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun setName(/*0*/ s: kotlin.String!): kotlin.Unit
public final fun test(/*0*/ s: j.Super): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class Nested2 {
public constructor Nested2()
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 final fun test(/*0*/ s: j.Super): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
}
}
@@ -5,8 +5,8 @@ import JavaClass
fun foo(javaClass: JavaClass) {
val v = javaClass.<!INVISIBLE_REFERENCE!>something<!>
javaClass.something = 1
javaClass.<!INVISIBLE_REFERENCE!>something<!>++
javaClass.<!INVISIBLE_REFERENCE!>something<!> = 1
javaClass.<!INVISIBLE_REFERENCE, INVISIBLE_REFERENCE!>something<!>++
}
// FILE: JavaClass.java