Minor, move tests about Java field and Kotlin property

Because the `fieldRename` directory was originally about cases when
private fields are renamed because of clashes.
This commit is contained in:
Alexander Udalov
2023-02-08 23:32:00 +01:00
parent 4b1f739c89
commit 4ad594a3cd
38 changed files with 527 additions and 396 deletions
@@ -0,0 +1,30 @@
// TARGET_BACKEND: JVM_IR
// Field VS property: case 3.1
// See KT-54393 for details
// FILE: VeryBase.kt
open class VeryBase {
val some = "FAIL"
}
// FILE: Base.java
public class Base extends VeryBase {
public String some = "OK";
public String foo() {
return some;
}
}
// FILE: Test.kt
class Derived : Base()
fun box(): String {
val first = Derived().some
if (first != "OK") return first
val d = Derived()
if (d::some.get() != "OK") return d::some.get()
d.some = "12"
if (d.foo() != "12") return "Error writing: ${d.foo()}"
return "OK"
}
@@ -0,0 +1,37 @@
// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND: JVM_IR
// IGNORE_BACKEND_FIR: JVM_IR
// FIR_STATUS: accesses companion property backing field statically and fails (does not work in K1/JVM too)
// FILE: Base.java
public class Base {
protected String TAG = "OK";
public String foo() {
return TAG;
}
}
// FILE: Sub.kt
class Sub : Base() {
companion object {
val TAG = "FAIL"
}
fun log() = TAG
fun logReference() = this::TAG.get()
fun logAssignment(): String {
TAG = "12"
if (foo() != "12") return "Error writing: ${foo()}"
return "OK"
}
}
fun box(): String {
if (Sub().log() != "OK") return Sub().log()
if (Sub().logReference() != "OK") return Sub().logReference()
return Sub().logAssignment()
}
@@ -0,0 +1,28 @@
// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND_K1: JVM_IR
// IGNORE_BACKEND_K2: JVM_IR
// tried to access field Derived.a from class DerivedKt
// FILE: BaseJava.java
public class BaseJava {
public String a = "OK";
public String foo() {
return a;
}
}
// FILE: Derived.kt
class Derived : BaseJava() {
private val a = "FAIL"
}
fun box(): String {
val first = Derived().a
if (first != "OK") return first
val d = Derived()
if (d::a.get() != "OK") return d::a.get()
d.a = "12"
if (d.foo() != "12") return "Error writing: ${d.foo()}"
return "OK"
}
@@ -0,0 +1,29 @@
// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND_K1: JVM_IR
// IGNORE_BACKEND_K2: JVM_IR
// tried to access field Derived.a from class DerivedKt
// FILE: BaseJava.java
public class BaseJava {
public String a = "OK";
public String foo() {
return a;
}
}
// FILE: Derived.kt
open class Derived : BaseJava() {
private val a = "FAIL"
}
fun <T : Derived> test(t: T): String {
val first = t.a
if (first != "OK") return first
if (t::a.get() != "OK") return t::a.get()
t.a = "12"
if (t.foo() != "12") return "Error writing: ${t.foo()}"
return "OK"
}
fun box(): String = test(Derived())
@@ -0,0 +1,27 @@
// TARGET_BACKEND: JVM_IR
// Field VS property: case 1.2
// See KT-54393 for details
// FILE: BaseJava.java
public class BaseJava {
public String a = "OK";
public String foo() {
return a;
}
}
// FILE: Derived.kt
class Derived : BaseJava() {
private val a get() = "FAIL"
}
fun box(): String {
val first = Derived().a
if (first != "OK") return first
val d = Derived()
if (d::a.get() != "OK") return d::a.get()
d.a = "12"
if (d.foo() != "12") return "Error writing: ${d.foo()}"
return "OK"
}
@@ -0,0 +1,24 @@
// TARGET_BACKEND: JVM_IR
// Field VS property: case "lateinit"
// FILE: BaseJava.java
public class BaseJava {
public String a = "FAIL";
public String fieldValue() {
return a;
}
}
// FILE: Derived.kt
class Derived : BaseJava() {
lateinit var a: String
}
fun box(): String {
val d = Derived()
d.a = "OK"
if ((d as BaseJava).a == "OK") return "FAIL (accidental shadowed field access #1)"
if (d.fieldValue() == "OK") return "FAIL (accidental shadowed field access #2)"
return d.a
}
@@ -0,0 +1,18 @@
// TARGET_BACKEND: JVM_IR
// Note: works accidentally via backing field access
// Field VS property: case 4.2
// More or less duplicates the case in KT-34943/KT-54393
// FILE: BaseJava.java
public class BaseJava {
public String a = "FAIL";
}
// FILE: Derived.kt
class Derived : BaseJava() {
private val a = "OK"
fun x() = a
}
fun box() = Derived().x()
@@ -0,0 +1,83 @@
FILE fqName:<root> fileName:/Derived.kt
CLASS CLASS name:Derived modality:FINAL visibility:public superTypes:[<root>.BaseJava]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Derived
CONSTRUCTOR visibility:public <> () returnType:<root>.Derived [primary]
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in <root>.BaseJava'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Derived modality:FINAL visibility:public superTypes:[<root>.BaseJava]'
PROPERTY name:a visibility:public modality:FINAL [var]
FIELD PROPERTY_BACKING_FIELD name:a type:kotlin.String visibility:private
EXPRESSION_BODY
CONST String type=kotlin.String value="OK"
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-a> visibility:public modality:FINAL <> ($this:<root>.Derived) returnType:kotlin.String
correspondingProperty: PROPERTY name:a visibility:public modality:FINAL [var]
$this: VALUE_PARAMETER name:<this> type:<root>.Derived
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun <get-a> (): kotlin.String declared in <root>.Derived'
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:a type:kotlin.String visibility:private' type=kotlin.String origin=null
receiver: GET_VAR '<this>: <root>.Derived declared in <root>.Derived.<get-a>' type=<root>.Derived origin=null
FUN DEFAULT_PROPERTY_ACCESSOR name:<set-a> visibility:public modality:FINAL <> ($this:<root>.Derived, <set-?>:kotlin.String) returnType:kotlin.Unit
correspondingProperty: PROPERTY name:a visibility:public modality:FINAL [var]
$this: VALUE_PARAMETER name:<this> type:<root>.Derived
VALUE_PARAMETER name:<set-?> index:0 type:kotlin.String
BLOCK_BODY
SET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:a type:kotlin.String visibility:private' type=kotlin.Unit origin=null
receiver: GET_VAR '<this>: <root>.Derived declared in <root>.Derived.<set-a>' type=<root>.Derived origin=null
value: GET_VAR '<set-?>: kotlin.String declared in <root>.Derived.<set-a>' type=kotlin.String origin=null
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean [fake_override,operator] declared in <root>.BaseJava
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
overridden:
public open fun hashCode (): kotlin.Int [fake_override] declared in <root>.BaseJava
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override]
overridden:
public open fun toString (): kotlin.String [fake_override] declared in <root>.BaseJava
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN name:box visibility:public modality:FINAL <> () returnType:kotlin.String
BLOCK_BODY
VAR name:first type:kotlin.String [val]
CALL 'public final fun <get-a> (): kotlin.String declared in <root>.Derived' type=kotlin.String origin=GET_PROPERTY
$this: CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in <root>.Derived' type=<root>.Derived origin=null
WHEN type=kotlin.Unit origin=IF
BRANCH
if: CALL 'public final fun not (): kotlin.Boolean [operator] declared in kotlin.Boolean' type=kotlin.Boolean origin=EXCLEQ
$this: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EXCLEQ
arg0: GET_VAR 'val first: kotlin.String [val] declared in <root>.box' type=kotlin.String origin=null
arg1: CONST String type=kotlin.String value="OK"
then: RETURN type=kotlin.Nothing from='public final fun box (): kotlin.String declared in <root>'
GET_VAR 'val first: kotlin.String [val] declared in <root>.box' type=kotlin.String origin=null
VAR name:d type:<root>.Derived [val]
CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in <root>.Derived' type=<root>.Derived origin=null
WHEN type=kotlin.Unit origin=IF
BRANCH
if: CALL 'public final fun not (): kotlin.Boolean [operator] declared in kotlin.Boolean' type=kotlin.Boolean origin=EXCLEQ
$this: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EXCLEQ
arg0: CALL 'public abstract fun get (): V of kotlin.reflect.KMutableProperty0 [expect,fake_override] declared in kotlin.reflect.KMutableProperty0' type=kotlin.String origin=null
$this: PROPERTY_REFERENCE 'public final a: kotlin.String [var]' field=null getter='public final fun <get-a> (): kotlin.String declared in <root>.Derived' setter='public final fun <set-a> (<set-?>: kotlin.String): kotlin.Unit declared in <root>.Derived' type=kotlin.reflect.KMutableProperty0<kotlin.String> origin=null
$this: GET_VAR 'val d: <root>.Derived [val] declared in <root>.box' type=<root>.Derived origin=null
arg1: CONST String type=kotlin.String value="OK"
then: RETURN type=kotlin.Nothing from='public final fun box (): kotlin.String declared in <root>'
CALL 'public abstract fun get (): V of kotlin.reflect.KMutableProperty0 [expect,fake_override] declared in kotlin.reflect.KMutableProperty0' type=kotlin.String origin=null
$this: PROPERTY_REFERENCE 'public final a: kotlin.String [var]' field=null getter='public final fun <get-a> (): kotlin.String declared in <root>.Derived' setter='public final fun <set-a> (<set-?>: kotlin.String): kotlin.Unit declared in <root>.Derived' type=kotlin.reflect.KMutableProperty0<kotlin.String> origin=null
$this: GET_VAR 'val d: <root>.Derived [val] declared in <root>.box' type=<root>.Derived origin=null
CALL 'public final fun <set-a> (<set-?>: kotlin.String): kotlin.Unit declared in <root>.Derived' type=kotlin.Unit origin=EQ
$this: GET_VAR 'val d: <root>.Derived [val] declared in <root>.box' type=<root>.Derived origin=null
<set-?>: CONST String type=kotlin.String value="12"
WHEN type=kotlin.Unit origin=IF
BRANCH
if: CALL 'public final fun not (): kotlin.Boolean [operator] declared in kotlin.Boolean' type=kotlin.Boolean origin=EXCLEQ
$this: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EXCLEQ
arg0: CALL 'public final fun <get-a> (): kotlin.String declared in <root>.Derived' type=kotlin.String origin=GET_PROPERTY
$this: GET_VAR 'val d: <root>.Derived [val] declared in <root>.box' type=<root>.Derived origin=null
arg1: CONST String type=kotlin.String value="12"
then: RETURN type=kotlin.Nothing from='public final fun box (): kotlin.String declared in <root>'
STRING_CONCATENATION type=kotlin.String
CONST String type=kotlin.String value="Error writing: "
CALL 'public final fun <get-a> (): kotlin.String declared in <root>.Derived' type=kotlin.String origin=GET_PROPERTY
$this: GET_VAR 'val d: <root>.Derived [val] declared in <root>.box' type=<root>.Derived origin=null
RETURN type=kotlin.Nothing from='public final fun box (): kotlin.String declared in <root>'
CONST String type=kotlin.String value="OK"
@@ -0,0 +1,88 @@
FILE fqName:<root> fileName:/Derived.kt
CLASS CLASS name:Derived modality:FINAL visibility:public superTypes:[<root>.BaseJava]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Derived
CONSTRUCTOR visibility:public <> () returnType:<root>.Derived [primary]
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in <root>.BaseJava'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Derived modality:FINAL visibility:public superTypes:[<root>.BaseJava]'
PROPERTY name:a visibility:public modality:FINAL [var]
FIELD PROPERTY_BACKING_FIELD name:a type:kotlin.String visibility:private
EXPRESSION_BODY
CONST String type=kotlin.String value="OK"
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-a> visibility:public modality:FINAL <> ($this:<root>.Derived) returnType:kotlin.String
correspondingProperty: PROPERTY name:a visibility:public modality:FINAL [var]
$this: VALUE_PARAMETER name:<this> type:<root>.Derived
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun <get-a> (): kotlin.String declared in <root>.Derived'
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:a type:kotlin.String visibility:private' type=kotlin.String origin=null
receiver: GET_VAR '<this>: <root>.Derived declared in <root>.Derived.<get-a>' type=<root>.Derived origin=null
FUN DEFAULT_PROPERTY_ACCESSOR name:<set-a> visibility:public modality:FINAL <> ($this:<root>.Derived, <set-?>:kotlin.String) returnType:kotlin.Unit
correspondingProperty: PROPERTY name:a visibility:public modality:FINAL [var]
$this: VALUE_PARAMETER name:<this> type:<root>.Derived
VALUE_PARAMETER name:<set-?> index:0 type:kotlin.String
BLOCK_BODY
SET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:a type:kotlin.String visibility:private' type=kotlin.Unit origin=null
receiver: GET_VAR '<this>: <root>.Derived declared in <root>.Derived.<set-a>' type=<root>.Derived origin=null
value: GET_VAR '<set-?>: kotlin.String declared in <root>.Derived.<set-a>' type=kotlin.String origin=null
PROPERTY FAKE_OVERRIDE name:a visibility:public modality:FINAL [fake_override,var]
overridden:
public final a: @[FlexibleNullability] kotlin.String? [var]
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean [fake_override,operator] declared in <root>.BaseJava
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
overridden:
public open fun hashCode (): kotlin.Int [fake_override] declared in <root>.BaseJava
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override]
overridden:
public open fun toString (): kotlin.String [fake_override] declared in <root>.BaseJava
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN name:box visibility:public modality:FINAL <> () returnType:kotlin.String
BLOCK_BODY
VAR name:first type:@[FlexibleNullability] kotlin.String? [val]
GET_FIELD 'FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:a type:@[FlexibleNullability] kotlin.String? visibility:public' type=@[FlexibleNullability] kotlin.String? origin=GET_PROPERTY
receiver: CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in <root>.Derived' type=<root>.Derived origin=null
WHEN type=kotlin.Unit origin=IF
BRANCH
if: CALL 'public final fun not (): kotlin.Boolean [operator] declared in kotlin.Boolean' type=kotlin.Boolean origin=EXCLEQ
$this: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EXCLEQ
arg0: GET_VAR 'val first: @[FlexibleNullability] kotlin.String? [val] declared in <root>.box' type=@[FlexibleNullability] kotlin.String? origin=null
arg1: CONST String type=kotlin.String value="OK"
then: RETURN type=kotlin.Nothing from='public final fun box (): kotlin.String declared in <root>'
TYPE_OP type=kotlin.String origin=IMPLICIT_NOTNULL typeOperand=kotlin.String
GET_VAR 'val first: @[FlexibleNullability] kotlin.String? [val] declared in <root>.box' type=@[FlexibleNullability] kotlin.String? origin=null
VAR name:d type:<root>.Derived [val]
CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in <root>.Derived' type=<root>.Derived origin=null
WHEN type=kotlin.Unit origin=IF
BRANCH
if: CALL 'public final fun not (): kotlin.Boolean [operator] declared in kotlin.Boolean' type=kotlin.Boolean origin=EXCLEQ
$this: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EXCLEQ
arg0: CALL 'public abstract fun get (): V of kotlin.reflect.KMutableProperty0 [expect,fake_override] declared in kotlin.reflect.KMutableProperty0' type=@[FlexibleNullability] kotlin.String? origin=null
$this: PROPERTY_REFERENCE 'public final a [fake_override,var]' field='FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:a type:@[FlexibleNullability] kotlin.String? visibility:public' getter=null setter=null type=kotlin.reflect.KMutableProperty0<@[FlexibleNullability] kotlin.String?> origin=null
$this: GET_VAR 'val d: <root>.Derived [val] declared in <root>.box' type=<root>.Derived origin=null
arg1: CONST String type=kotlin.String value="OK"
then: RETURN type=kotlin.Nothing from='public final fun box (): kotlin.String declared in <root>'
TYPE_OP type=kotlin.String origin=IMPLICIT_NOTNULL typeOperand=kotlin.String
CALL 'public abstract fun get (): V of kotlin.reflect.KMutableProperty0 [expect,fake_override] declared in kotlin.reflect.KMutableProperty0' type=@[FlexibleNullability] kotlin.String? origin=null
$this: PROPERTY_REFERENCE 'public final a [fake_override,var]' field='FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:a type:@[FlexibleNullability] kotlin.String? visibility:public' getter=null setter=null type=kotlin.reflect.KMutableProperty0<@[FlexibleNullability] kotlin.String?> origin=null
$this: GET_VAR 'val d: <root>.Derived [val] declared in <root>.box' type=<root>.Derived origin=null
SET_FIELD 'FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:a type:@[FlexibleNullability] kotlin.String? visibility:public' type=kotlin.Unit origin=EQ
receiver: GET_VAR 'val d: <root>.Derived [val] declared in <root>.box' type=<root>.Derived origin=null
value: CONST String type=kotlin.String value="12"
WHEN type=kotlin.Unit origin=IF
BRANCH
if: CALL 'public final fun not (): kotlin.Boolean [operator] declared in kotlin.Boolean' type=kotlin.Boolean origin=EXCLEQ
$this: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EXCLEQ
arg0: GET_FIELD 'FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:a type:@[FlexibleNullability] kotlin.String? visibility:public' type=@[FlexibleNullability] kotlin.String? origin=GET_PROPERTY
receiver: GET_VAR 'val d: <root>.Derived [val] declared in <root>.box' type=<root>.Derived origin=null
arg1: CONST String type=kotlin.String value="12"
then: RETURN type=kotlin.Nothing from='public final fun box (): kotlin.String declared in <root>'
STRING_CONCATENATION type=kotlin.String
CONST String type=kotlin.String value="Error writing: "
GET_FIELD 'FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:a type:@[FlexibleNullability] kotlin.String? visibility:public' type=@[FlexibleNullability] kotlin.String? origin=GET_PROPERTY
receiver: GET_VAR 'val d: <root>.Derived [val] declared in <root>.box' type=<root>.Derived origin=null
RETURN type=kotlin.Nothing from='public final fun box (): kotlin.String declared in <root>'
CONST String type=kotlin.String value="OK"
@@ -0,0 +1,25 @@
// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND_K1: JVM_IR
// Field VS property: case 4.1
// See KT-50082
// DUMP_IR
// FILE: BaseJava.java
public class BaseJava {
public String a = "FAIL";
}
// FILE: Derived.kt
class Derived : BaseJava() {
var a = "OK"
}
fun box(): String {
val first = Derived().a
if (first != "OK") return first
val d = Derived()
if (d::a.get() != "OK") return d::a.get()
d.a = "12"
if (d.a != "12") return "Error writing: ${d.a}"
return "OK"
}
@@ -0,0 +1,58 @@
FILE fqName:<root> fileName:/Derived.kt
CLASS CLASS name:Derived modality:FINAL visibility:public superTypes:[<root>.BaseJava]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Derived
CONSTRUCTOR visibility:public <> () returnType:<root>.Derived [primary]
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in <root>.BaseJava'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Derived modality:FINAL visibility:public superTypes:[<root>.BaseJava]'
PROPERTY name:a visibility:private modality:FINAL [val]
FIELD PROPERTY_BACKING_FIELD name:a type:kotlin.String visibility:private [final]
EXPRESSION_BODY
CONST String type=kotlin.String value="FAIL"
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-a> visibility:private modality:FINAL <> ($this:<root>.Derived) returnType:kotlin.String
correspondingProperty: PROPERTY name:a visibility:private modality:FINAL [val]
$this: VALUE_PARAMETER name:<this> type:<root>.Derived
BLOCK_BODY
RETURN type=kotlin.Nothing from='private final fun <get-a> (): kotlin.String declared in <root>.Derived'
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:a type:kotlin.String visibility:private [final]' type=kotlin.String origin=null
receiver: GET_VAR '<this>: <root>.Derived declared in <root>.Derived.<get-a>' type=<root>.Derived origin=null
PROPERTY name:b visibility:private modality:FINAL [val]
FIELD PROPERTY_BACKING_FIELD name:b type:kotlin.String visibility:private [final]
EXPRESSION_BODY
CONST String type=kotlin.String value="FAIL"
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-b> visibility:private modality:FINAL <> ($this:<root>.Derived) returnType:kotlin.String
correspondingProperty: PROPERTY name:b visibility:private modality:FINAL [val]
$this: VALUE_PARAMETER name:<this> type:<root>.Derived
BLOCK_BODY
RETURN type=kotlin.Nothing from='private final fun <get-b> (): kotlin.String declared in <root>.Derived'
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:b type:kotlin.String visibility:private [final]' type=kotlin.String origin=null
receiver: GET_VAR '<this>: <root>.Derived declared in <root>.Derived.<get-b>' type=<root>.Derived origin=null
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean [fake_override,operator] declared in <root>.BaseJava
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
overridden:
public open fun hashCode (): kotlin.Int [fake_override] declared in <root>.BaseJava
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override]
overridden:
public open fun toString (): kotlin.String [fake_override] declared in <root>.BaseJava
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN name:box visibility:public modality:FINAL <> () returnType:kotlin.String
BLOCK_BODY
VAR name:d type:<root>.Derived [val]
CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in <root>.Derived' type=<root>.Derived origin=null
RETURN type=kotlin.Nothing from='public final fun box (): kotlin.String declared in <root>'
CALL 'public final fun plus (other: kotlin.Any?): kotlin.String [operator] declared in kotlin.String' type=kotlin.String origin=PLUS
$this: CALL 'public abstract fun get (): V of kotlin.reflect.KMutableProperty0 [expect,fake_override] declared in kotlin.reflect.KMutableProperty0' type=@[FlexibleNullability] kotlin.String? origin=null
$this: PROPERTY_REFERENCE 'public open a: @[FlexibleNullability] kotlin.String? [var]' field='FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:a type:@[FlexibleNullability] kotlin.String? visibility:public' getter='public open fun <get-a> (): @[FlexibleNullability] kotlin.String? declared in <root>.BaseJava' setter='public open fun <set-a> (<set-?>: @[FlexibleNullability] kotlin.String?): kotlin.Unit declared in <root>.BaseJava' type=kotlin.reflect.KMutableProperty0<@[FlexibleNullability] kotlin.String?> origin=null
<1>: <none>
$this: TYPE_OP type=<root>.BaseJava origin=IMPLICIT_CAST typeOperand=<root>.BaseJava
GET_VAR 'val d: <root>.Derived [val] declared in <root>.box' type=<root>.Derived origin=null
other: CALL 'public abstract fun get (): V of kotlin.reflect.KMutableProperty0 [expect,fake_override] declared in kotlin.reflect.KMutableProperty0' type=@[FlexibleNullability] kotlin.String? origin=null
$this: PROPERTY_REFERENCE 'public/*package*/ open b: @[FlexibleNullability] kotlin.String? [var]' field='FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:b type:@[FlexibleNullability] kotlin.String? visibility:public/*package*/' getter='public/*package*/ open fun <get-b> (): @[FlexibleNullability] kotlin.String? declared in <root>.BaseJava' setter='public/*package*/ open fun <set-b> (<set-?>: @[FlexibleNullability] kotlin.String?): kotlin.Unit declared in <root>.BaseJava' type=kotlin.reflect.KMutableProperty0<@[FlexibleNullability] kotlin.String?> origin=null
<1>: <none>
$this: TYPE_OP type=<root>.BaseJava origin=IMPLICIT_CAST typeOperand=<root>.BaseJava
GET_VAR 'val d: <root>.Derived [val] declared in <root>.box' type=<root>.Derived origin=null
@@ -0,0 +1,61 @@
FILE fqName:<root> fileName:/Derived.kt
CLASS CLASS name:Derived modality:FINAL visibility:public superTypes:[<root>.BaseJava]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Derived
CONSTRUCTOR visibility:public <> () returnType:<root>.Derived [primary]
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in <root>.BaseJava'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Derived modality:FINAL visibility:public superTypes:[<root>.BaseJava]'
PROPERTY name:a visibility:private modality:FINAL [val]
FIELD PROPERTY_BACKING_FIELD name:a type:kotlin.String visibility:private [final]
EXPRESSION_BODY
CONST String type=kotlin.String value="FAIL"
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-a> visibility:private modality:FINAL <> ($this:<root>.Derived) returnType:kotlin.String
correspondingProperty: PROPERTY name:a visibility:private modality:FINAL [val]
$this: VALUE_PARAMETER name:<this> type:<root>.Derived
BLOCK_BODY
RETURN type=kotlin.Nothing from='private final fun <get-a> (): kotlin.String declared in <root>.Derived'
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:a type:kotlin.String visibility:private [final]' type=kotlin.String origin=null
receiver: GET_VAR '<this>: <root>.Derived declared in <root>.Derived.<get-a>' type=<root>.Derived origin=null
PROPERTY name:b visibility:private modality:FINAL [val]
FIELD PROPERTY_BACKING_FIELD name:b type:kotlin.String visibility:private [final]
EXPRESSION_BODY
CONST String type=kotlin.String value="FAIL"
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-b> visibility:private modality:FINAL <> ($this:<root>.Derived) returnType:kotlin.String
correspondingProperty: PROPERTY name:b visibility:private modality:FINAL [val]
$this: VALUE_PARAMETER name:<this> type:<root>.Derived
BLOCK_BODY
RETURN type=kotlin.Nothing from='private final fun <get-b> (): kotlin.String declared in <root>.Derived'
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:b type:kotlin.String visibility:private [final]' type=kotlin.String origin=null
receiver: GET_VAR '<this>: <root>.Derived declared in <root>.Derived.<get-b>' type=<root>.Derived origin=null
PROPERTY FAKE_OVERRIDE name:a visibility:public modality:FINAL [fake_override,var]
overridden:
public final a: @[FlexibleNullability] kotlin.String? [var]
PROPERTY FAKE_OVERRIDE name:b visibility:public/*package*/ modality:FINAL [fake_override,var]
overridden:
public/*package*/ final b: @[FlexibleNullability] kotlin.String? [var]
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean [fake_override,operator] declared in <root>.BaseJava
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
overridden:
public open fun hashCode (): kotlin.Int [fake_override] declared in <root>.BaseJava
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override]
overridden:
public open fun toString (): kotlin.String [fake_override] declared in <root>.BaseJava
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN name:box visibility:public modality:FINAL <> () returnType:kotlin.String
BLOCK_BODY
VAR name:d type:<root>.Derived [val]
CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in <root>.Derived' type=<root>.Derived origin=null
RETURN type=kotlin.Nothing from='public final fun box (): kotlin.String declared in <root>'
CALL 'public final fun plus (other: kotlin.Any?): kotlin.String [operator] declared in kotlin.String' type=kotlin.String origin=PLUS
$this: TYPE_OP type=kotlin.String origin=IMPLICIT_NOTNULL typeOperand=kotlin.String
CALL 'public abstract fun get (): V of kotlin.reflect.KMutableProperty0 [expect,fake_override] declared in kotlin.reflect.KMutableProperty0' type=@[FlexibleNullability] kotlin.String? origin=null
$this: PROPERTY_REFERENCE 'public final a [fake_override,var]' field='FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:a type:@[FlexibleNullability] kotlin.String? visibility:public' getter=null setter=null type=kotlin.reflect.KMutableProperty0<@[FlexibleNullability] kotlin.String?> origin=null
$this: GET_VAR 'val d: <root>.Derived [val] declared in <root>.box' type=<root>.Derived origin=null
other: CALL 'public abstract fun get (): V of kotlin.reflect.KMutableProperty0 [expect,fake_override] declared in kotlin.reflect.KMutableProperty0' type=@[FlexibleNullability] kotlin.String? origin=null
$this: PROPERTY_REFERENCE 'public/*package*/ final b [fake_override,var]' field='FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:b type:@[FlexibleNullability] kotlin.String? visibility:public/*package*/' getter=null setter=null type=kotlin.reflect.KMutableProperty0<@[FlexibleNullability] kotlin.String?> origin=null
$this: GET_VAR 'val d: <root>.Derived [val] declared in <root>.box' type=<root>.Derived origin=null
@@ -0,0 +1,20 @@
// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND_K1: JVM_IR
// IGNORE_BACKEND_K2: JVM_IR
// FIR status: fails because of incorrect receiver in bytecode
// Field VS property: case "reference"
// FILE: BaseJava.java
public class BaseJava {
public String a = "OK";
}
// FILE: Derived.kt
class Derived : BaseJava() {
private val a = "FAIL"
}
fun box(): String {
val d = Derived()
return d::a.get()
}
@@ -0,0 +1,25 @@
// TARGET_BACKEND: JVM_IR
// FILE: Jaba.java
package base;
public class Jaba {
protected String a = "FAIL";
}
// FILE: test.kt
import base.Jaba
fun box(): String {
val x = object : Jaba() {
private val a: String = "OK"
inner class S {
fun foo() = ::a.get()
}
fun bar() = S().foo()
}
return x.bar()
}
@@ -0,0 +1,26 @@
// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND_K1: JVM_IR
// IGNORE_BACKEND_K2: JVM_IR
// tried to access field My.b from class Some
// FILE: Jaba.java
public class Jaba {
public String a = "O";
public String b = "";
}
// FILE: test.kt
open class My : Jaba() {
private val a: String = "FAIL"
private val b: String = "FAIL"
}
class Some : My() {
fun soo(): String {
super<My>.b = "K"
return super<My>.a + super<My>.b
}
}
fun box(): String = Some().soo()
@@ -0,0 +1,23 @@
// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND_K1: JVM_IR
// IGNORE_BACKEND_K2: JVM_IR
// tried to access field My.a from class TestKt
// FILE: Jaba.java
public class Jaba {
public String a = "OK";
}
// FILE: test.kt
class My : Jaba() {
private val a: String = "FAIL"
operator fun plus(my: My) = my
}
fun create(): My? = My()
fun box(): String {
return (create() ?: My()).a
}
@@ -0,0 +1,27 @@
// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND_K1: JVM_IR
// IGNORE_BACKEND_K2: JVM_IR
// tried to access field My.b from class TestKt
// FILE: Jaba.java
public class Jaba {
public String a = "O";
public String b = "";
}
// FILE: test.kt
class My : Jaba() {
private val a: String = "FAIL"
private val b: String = "FAIL"
}
fun test(j: Any): String {
if (j is My) {
j.b = "K"
return j.a + j.b
}
return "NO SMARTCAST"
}
fun box(): String = test(My())
@@ -0,0 +1,26 @@
// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND_K1: JVM_IR
// IGNORE_BACKEND_K2: JVM_IR
// tried to access field B.f from class TestKt
// FILE: A.java
public class A {
String f = "OK";
}
// FILE: B.kt
open class B : A() {
private val f = "FAIL"
}
// FILE: C.java
public class C extends B {}
// FILE: test.kt
fun box(): String {
return C().f
}
@@ -0,0 +1,38 @@
// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND_K1: JVM_IR
// IGNORE_BACKEND_K2: JVM_IR
// tried to access field base.B.f from class TestKt
// FILE: Y.java
package base;
class Y {
public String f = "OK";
}
// FILE: A.java
package base;
public class A extends Y {}
// FILE: B.kt
package base
open class B : A() {
private val f = "FAIL"
}
// FILE: C.java
import base.B;
public class C extends B {}
// FILE: test.kt
fun box(): String {
return C().f
}
@@ -0,0 +1,23 @@
// TARGET_BACKEND: JVM_IR
// Field VS property: case 2.1
// See KT-54393 for details
// FILE: BaseJava.java
public class BaseJava {
private String a = "FAIL";
}
// FILE: Derived.kt
class Derived : BaseJava() {
var a = "OK"
}
fun box(): String {
val first = Derived().a
if (first != "OK") return first
val d = Derived()
if (d::a.get() != "OK") return d::a.get()
d.a = "12"
if (d.a != "12") return "Error writing: ${d.a}"
return "OK"
}
@@ -0,0 +1,25 @@
// TARGET_BACKEND: JVM_IR
// Field VS property: case "reference", field is invisible
// FILE: BaseJava.java
package base;
public class BaseJava {
String a = "FAIL";
}
// FILE: Derived.kt
package derived
import base.BaseJava
class Derived : BaseJava() {
val a = "OK"
}
fun box(): String {
val d = Derived()
return d::a.get()
}
@@ -0,0 +1,32 @@
// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND_K1: JVM_IR
// IGNORE_BACKEND_K2: JVM_IR
// tried to access field derived.Intermediate.a from class derived.Derived
// Field VS property: case "reference", protected field, invisible property
// FILE: BaseJava.java
package base;
public class BaseJava {
protected String a = "OK";
}
// FILE: Derived.kt
package derived
import base.BaseJava
open class Intermediate : BaseJava() {
private val a = "FAIL"
}
class Derived : Intermediate() {
fun foo() = a
}
fun box(): String {
val d = Derived()
return d.foo()
}
@@ -0,0 +1,31 @@
// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND_K1: JVM_IR
// IGNORE_BACKEND_K2: JVM_IR
// tried to access field base.Intermediate.a from class base.Derived$foo$1
// Field VS property: case "reference", protected field in the same package, invisible property
// FILE: BaseJava.java
package base;
public class BaseJava {
protected String a = "OK";
}
// FILE: Derived.kt
package base
// Note: this test should report an error when we are in different package
open class Intermediate : BaseJava() {
private val a = "FAIL"
}
class Derived : Intermediate() {
fun foo() = this::a.get()
}
fun box(): String {
val d = Derived()
return d.foo()
}
@@ -0,0 +1,37 @@
// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND_K1: JVM_IR
// IGNORE_BACKEND_K2: JVM_IR
// tried to access field derived.Intermediate.a from class derived.Derived
// Field VS property: case "reference", protected field, invisible property
// FILE: BaseJava.java
package base;
public class BaseJava {
protected String a = "";
}
// FILE: Derived.kt
package derived
import base.BaseJava
open class Intermediate : BaseJava() {
private val a = "FAIL"
}
class Derived : Intermediate() {
fun foo() = a
fun bar() {
a = "OK"
}
}
fun box(): String {
val d = Derived()
d.bar()
return d.foo()
}
@@ -0,0 +1,20 @@
// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND_K1: JVM_IR
// Field VS property: case "reference", protected field, visible property
// FILE: BaseJava.java
public class BaseJava {
protected String a = "FAIL";
}
// FILE: Derived.kt
class Derived : BaseJava() {
private val a = "OK"
fun foo() = this::a.get()
}
fun box(): String {
val d = Derived()
return d.foo()
}
@@ -0,0 +1,24 @@
// TARGET_BACKEND: JVM_IR
// FILE: BaseJava.java
package base;
public class BaseJava {
protected String a = "OK";
}
// FILE: Derived.kt
package derived
import base.BaseJava
class Derived : BaseJava() {
fun foo() = ::a.get()
}
fun box(): String {
val d = Derived()
return d.foo()
}