K2: reproduce KT-61974

This commit is contained in:
Mikhail Glukhikh
2023-09-28 11:27:58 +02:00
committed by Space Team
parent 0d98995a8e
commit 8e577e101e
9 changed files with 369 additions and 0 deletions
@@ -2682,6 +2682,12 @@ public class FirLightTreeJvmIrTextTestGenerated extends AbstractFirLightTreeJvmI
runTest("compiler/testData/ir/irText/firProblems/deprecated.kt");
}
@Test
@TestMetadata("elvisOnBackingFieldInGetter.kt")
public void testElvisOnBackingFieldInGetter() throws Exception {
runTest("compiler/testData/ir/irText/firProblems/elvisOnBackingFieldInGetter.kt");
}
@Test
@TestMetadata("emptyWhen.kt")
public void testEmptyWhen() throws Exception {
@@ -2682,6 +2682,12 @@ public class FirPsiJvmIrTextTestGenerated extends AbstractFirPsiJvmIrTextTest {
runTest("compiler/testData/ir/irText/firProblems/deprecated.kt");
}
@Test
@TestMetadata("elvisOnBackingFieldInGetter.kt")
public void testElvisOnBackingFieldInGetter() throws Exception {
runTest("compiler/testData/ir/irText/firProblems/elvisOnBackingFieldInGetter.kt");
}
@Test
@TestMetadata("emptyWhen.kt")
public void testEmptyWhen() throws Exception {
@@ -0,0 +1,98 @@
FILE fqName:<root> fileName:/elvisOnBackingFieldInGetter.kt
CLASS CLASS name:Test modality:FINAL visibility:public superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Test
CONSTRUCTOR visibility:public <> () returnType:<root>.Test [primary]
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () declared in kotlin.Any'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Test modality:FINAL visibility:public superTypes:[kotlin.Any]'
PROPERTY name:resourceTable visibility:public modality:FINAL [var]
FIELD PROPERTY_BACKING_FIELD name:resourceTable type:<root>.ResourceTable? visibility:private
EXPRESSION_BODY
CONST Null type=kotlin.Nothing? value=null
FUN name:<get-resourceTable> visibility:public modality:FINAL <> ($this:<root>.Test) returnType:<root>.ResourceTable?
correspondingProperty: PROPERTY name:resourceTable visibility:public modality:FINAL [var]
$this: VALUE_PARAMETER name:<this> type:<root>.Test
BLOCK_BODY
WHEN type=kotlin.Unit origin=IF
BRANCH
if: CALL 'public final fun not (): kotlin.Boolean 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 PROPERTY_BACKING_FIELD name:resourceTable type:<root>.ResourceTable? visibility:private' type=<root>.ResourceTable? origin=GET_PROPERTY
receiver: GET_VAR '<this>: <root>.Test declared in <root>.Test.<get-resourceTable>' type=<root>.Test origin=null
arg1: CONST Null type=kotlin.Nothing? value=null
then: BLOCK type=kotlin.Unit origin=null
RETURN type=kotlin.Nothing from='public final fun <get-resourceTable> (): <root>.ResourceTable? declared in <root>.Test'
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:resourceTable type:<root>.ResourceTable? visibility:private' type=<root>.ResourceTable? origin=GET_PROPERTY
receiver: GET_VAR '<this>: <root>.Test declared in <root>.Test.<get-resourceTable>' type=<root>.Test origin=null
VAR name:fileData type:kotlin.String? [val]
CALL 'public final fun getFileData (): kotlin.String? declared in <root>.Test' type=kotlin.String? origin=null
$this: GET_VAR '<this>: <root>.Test declared in <root>.Test.<get-resourceTable>' type=<root>.Test origin=null
WHEN type=kotlin.Unit origin=IF
BRANCH
if: CALL 'public final fun not (): kotlin.Boolean 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 fileData: kotlin.String? declared in <root>.Test.<get-resourceTable>' type=kotlin.String? origin=null
arg1: CONST Null type=kotlin.Nothing? value=null
then: BLOCK type=kotlin.Unit origin=null
SET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:resourceTable type:<root>.ResourceTable? visibility:private' type=kotlin.Unit origin=EQ
receiver: GET_VAR '<this>: <root>.Test declared in <root>.Test.<get-resourceTable>' type=<root>.Test origin=null
value: CONSTRUCTOR_CALL 'public constructor <init> () declared in <root>.ResourceTable' type=<root>.ResourceTable origin=null
RETURN type=kotlin.Nothing from='public final fun <get-resourceTable> (): <root>.ResourceTable? declared in <root>.Test'
BLOCK type=<root>.ResourceTable origin=ELVIS
VAR IR_TEMPORARY_VARIABLE name:tmp_0 type:kotlin.Nothing? [val]
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:resourceTable type:<root>.ResourceTable? visibility:private' type=<root>.ResourceTable? origin=GET_PROPERTY
receiver: GET_VAR '<this>: <root>.Test declared in <root>.Test.<get-resourceTable>' type=<root>.Test origin=null
WHEN type=<root>.ResourceTable origin=null
BRANCH
if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ
arg0: GET_VAR 'val tmp_0: kotlin.Nothing? declared in <root>.Test.<get-resourceTable>' type=kotlin.Nothing? origin=null
arg1: CONST Null type=kotlin.Nothing? value=null
then: CONSTRUCTOR_CALL 'public constructor <init> () declared in <root>.ResourceTable' type=<root>.ResourceTable origin=null
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: GET_VAR 'val tmp_0: kotlin.Nothing? declared in <root>.Test.<get-resourceTable>' type=kotlin.Nothing? origin=null
FUN DEFAULT_PROPERTY_ACCESSOR name:<set-resourceTable> visibility:public modality:FINAL <> ($this:<root>.Test, <set-?>:<root>.ResourceTable?) returnType:kotlin.Unit
correspondingProperty: PROPERTY name:resourceTable visibility:public modality:FINAL [var]
$this: VALUE_PARAMETER name:<this> type:<root>.Test
VALUE_PARAMETER name:<set-?> index:0 type:<root>.ResourceTable?
BLOCK_BODY
SET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:resourceTable type:<root>.ResourceTable? visibility:private' type=kotlin.Unit origin=null
receiver: GET_VAR '<this>: <root>.Test declared in <root>.Test.<set-resourceTable>' type=<root>.Test origin=null
value: GET_VAR '<set-?>: <root>.ResourceTable? declared in <root>.Test.<set-resourceTable>' type=<root>.ResourceTable? origin=null
FUN name:getFileData visibility:public modality:FINAL <> ($this:<root>.Test) returnType:kotlin.String?
$this: VALUE_PARAMETER name:<this> type:<root>.Test
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun getFileData (): kotlin.String? declared in <root>.Test'
CONST String type=kotlin.String value=""
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 declared in kotlin.Any
$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 declared in kotlin.Any
$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 declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
CLASS CLASS name:ResourceTable modality:FINAL visibility:public superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.ResourceTable
CONSTRUCTOR visibility:public <> () returnType:<root>.ResourceTable [primary]
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () declared in kotlin.Any'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:ResourceTable modality:FINAL visibility:public superTypes:[kotlin.Any]'
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 declared in kotlin.Any
$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 declared in kotlin.Any
$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 declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
@@ -0,0 +1,45 @@
class Test {
constructor() /* primary */ {
super/*Any*/()
/* <init>() */
}
var resourceTable: ResourceTable?
field = null
get(): ResourceTable? {
when {
EQEQ(arg0 = <this>.#resourceTable, arg1 = null).not() -> { // BLOCK
return <this>.#resourceTable
}
}
val fileData: String? = <this>.getFileData()
when {
EQEQ(arg0 = fileData, arg1 = null).not() -> { // BLOCK
<this>.#resourceTable = ResourceTable()
}
}
return { // BLOCK
val <elvis>: Nothing? = <this>.#resourceTable
when {
EQEQ(arg0 = <elvis>, arg1 = null) -> ResourceTable()
else -> <elvis>
}
}
}
set
fun getFileData(): String? {
return ""
}
}
class ResourceTable {
constructor() /* primary */ {
super/*Any*/()
/* <init>() */
}
}
@@ -0,0 +1,98 @@
FILE fqName:<root> fileName:/elvisOnBackingFieldInGetter.kt
CLASS CLASS name:Test modality:FINAL visibility:public superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Test
CONSTRUCTOR visibility:public <> () returnType:<root>.Test [primary]
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () declared in kotlin.Any'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Test modality:FINAL visibility:public superTypes:[kotlin.Any]'
PROPERTY name:resourceTable visibility:public modality:FINAL [var]
FIELD PROPERTY_BACKING_FIELD name:resourceTable type:<root>.ResourceTable? visibility:private
EXPRESSION_BODY
CONST Null type=kotlin.Nothing? value=null
FUN name:<get-resourceTable> visibility:public modality:FINAL <> ($this:<root>.Test) returnType:<root>.ResourceTable?
correspondingProperty: PROPERTY name:resourceTable visibility:public modality:FINAL [var]
$this: VALUE_PARAMETER name:<this> type:<root>.Test
BLOCK_BODY
WHEN type=kotlin.Unit origin=IF
BRANCH
if: CALL 'public final fun not (): kotlin.Boolean 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 PROPERTY_BACKING_FIELD name:resourceTable type:<root>.ResourceTable? visibility:private' type=<root>.ResourceTable? origin=null
receiver: GET_VAR '<this>: <root>.Test declared in <root>.Test.<get-resourceTable>' type=<root>.Test origin=null
arg1: CONST Null type=kotlin.Nothing? value=null
then: BLOCK type=kotlin.Unit origin=null
RETURN type=kotlin.Nothing from='public final fun <get-resourceTable> (): <root>.ResourceTable? declared in <root>.Test'
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:resourceTable type:<root>.ResourceTable? visibility:private' type=<root>.ResourceTable? origin=null
receiver: GET_VAR '<this>: <root>.Test declared in <root>.Test.<get-resourceTable>' type=<root>.Test origin=null
VAR name:fileData type:kotlin.String? [val]
CALL 'public final fun getFileData (): kotlin.String? declared in <root>.Test' type=kotlin.String? origin=null
$this: GET_VAR '<this>: <root>.Test declared in <root>.Test.<get-resourceTable>' type=<root>.Test origin=null
WHEN type=kotlin.Unit origin=IF
BRANCH
if: CALL 'public final fun not (): kotlin.Boolean 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 fileData: kotlin.String? declared in <root>.Test.<get-resourceTable>' type=kotlin.String? origin=null
arg1: CONST Null type=kotlin.Nothing? value=null
then: BLOCK type=kotlin.Unit origin=null
SET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:resourceTable type:<root>.ResourceTable? visibility:private' type=kotlin.Unit origin=EQ
receiver: GET_VAR '<this>: <root>.Test declared in <root>.Test.<get-resourceTable>' type=<root>.Test origin=null
value: CONSTRUCTOR_CALL 'public constructor <init> () declared in <root>.ResourceTable' type=<root>.ResourceTable origin=null
RETURN type=kotlin.Nothing from='public final fun <get-resourceTable> (): <root>.ResourceTable? declared in <root>.Test'
BLOCK type=<root>.ResourceTable? origin=ELVIS
VAR IR_TEMPORARY_VARIABLE name:tmp_0 type:<root>.ResourceTable? [val]
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:resourceTable type:<root>.ResourceTable? visibility:private' type=<root>.ResourceTable? origin=null
receiver: GET_VAR '<this>: <root>.Test declared in <root>.Test.<get-resourceTable>' type=<root>.Test origin=null
WHEN type=<root>.ResourceTable? origin=null
BRANCH
if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ
arg0: GET_VAR 'val tmp_0: <root>.ResourceTable? declared in <root>.Test.<get-resourceTable>' type=<root>.ResourceTable? origin=null
arg1: CONST Null type=kotlin.Nothing? value=null
then: CONSTRUCTOR_CALL 'public constructor <init> () declared in <root>.ResourceTable' type=<root>.ResourceTable origin=null
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: GET_VAR 'val tmp_0: <root>.ResourceTable? declared in <root>.Test.<get-resourceTable>' type=<root>.ResourceTable? origin=null
FUN DEFAULT_PROPERTY_ACCESSOR name:<set-resourceTable> visibility:public modality:FINAL <> ($this:<root>.Test, <set-?>:<root>.ResourceTable?) returnType:kotlin.Unit
correspondingProperty: PROPERTY name:resourceTable visibility:public modality:FINAL [var]
$this: VALUE_PARAMETER name:<this> type:<root>.Test
VALUE_PARAMETER name:<set-?> index:0 type:<root>.ResourceTable?
BLOCK_BODY
SET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:resourceTable type:<root>.ResourceTable? visibility:private' type=kotlin.Unit origin=null
receiver: GET_VAR '<this>: <root>.Test declared in <root>.Test.<set-resourceTable>' type=<root>.Test origin=null
value: GET_VAR '<set-?>: <root>.ResourceTable? declared in <root>.Test.<set-resourceTable>' type=<root>.ResourceTable? origin=null
FUN name:getFileData visibility:public modality:FINAL <> ($this:<root>.Test) returnType:kotlin.String?
$this: VALUE_PARAMETER name:<this> type:<root>.Test
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun getFileData (): kotlin.String? declared in <root>.Test'
CONST String type=kotlin.String value=""
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 declared in kotlin.Any
$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 declared in kotlin.Any
$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 declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
CLASS CLASS name:ResourceTable modality:FINAL visibility:public superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.ResourceTable
CONSTRUCTOR visibility:public <> () returnType:<root>.ResourceTable [primary]
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () declared in kotlin.Any'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:ResourceTable modality:FINAL visibility:public superTypes:[kotlin.Any]'
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 declared in kotlin.Any
$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 declared in kotlin.Any
$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 declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
@@ -0,0 +1,20 @@
// ISSUE: KT-61974
// TARGET_BACKEND: JVM
class Test {
var resourceTable: ResourceTable? = null
get() {
if (field != null) {
return field
}
val fileData = getFileData()
if (fileData != null) {
field = ResourceTable()
}
return field ?: ResourceTable()
}
fun getFileData(): String? = ""
}
class ResourceTable
@@ -0,0 +1,45 @@
class Test {
constructor() /* primary */ {
super/*Any*/()
/* <init>() */
}
var resourceTable: ResourceTable?
field = null
get(): ResourceTable? {
when {
EQEQ(arg0 = <this>.#resourceTable, arg1 = null).not() -> { // BLOCK
return <this>.#resourceTable
}
}
val fileData: String? = <this>.getFileData()
when {
EQEQ(arg0 = fileData, arg1 = null).not() -> { // BLOCK
<this>.#resourceTable = ResourceTable()
}
}
return { // BLOCK
val tmp0_elvis_lhs: ResourceTable? = <this>.#resourceTable
when {
EQEQ(arg0 = tmp0_elvis_lhs, arg1 = null) -> ResourceTable()
else -> tmp0_elvis_lhs
}
}
}
set
fun getFileData(): String? {
return ""
}
}
class ResourceTable {
constructor() /* primary */ {
super/*Any*/()
/* <init>() */
}
}
@@ -0,0 +1,45 @@
// CHECK:
// Mangled name: ResourceTable
// Public signature: /ResourceTable|null[0]
class ResourceTable {
// CHECK:
// Mangled name: ResourceTable#<init>(){}
// Public signature: /ResourceTable.<init>|-5645683436151566731[0]
// Public signature debug description: <init>(){}
constructor() /* primary */
}
// CHECK:
// Mangled name: Test
// Public signature: /Test|null[0]
class Test {
// CHECK:
// Mangled name: Test{}resourceTable
// Public signature: /Test.resourceTable|5106462391401126974[0]
// Public signature debug description: {}resourceTable
var resourceTable: ResourceTable?
// CHECK JVM_IR:
// Mangled name: Test#<get-resourceTable>(){}ResourceTable?
// Public signature: /Test.resourceTable.<get-resourceTable>|-8031293433039158174[0]
// Public signature debug description: <get-resourceTable>(){}ResourceTable?
get(): ResourceTable?
// CHECK:
// Mangled name: Test#<set-resourceTable>(ResourceTable?){}
// Public signature: /Test.resourceTable.<set-resourceTable>|-5872518901213324823[0]
// Public signature debug description: <set-resourceTable>(ResourceTable?){}
set
// CHECK:
// Mangled name: Test#<init>(){}
// Public signature: /Test.<init>|-5645683436151566731[0]
// Public signature debug description: <init>(){}
constructor() /* primary */
// CHECK JVM_IR:
// Mangled name: Test#getFileData(){}kotlin.String?
// Public signature: /Test.getFileData|5079278953481470574[0]
// Public signature debug description: getFileData(){}kotlin.String?
fun getFileData(): String?
}
@@ -2682,6 +2682,12 @@ public class ClassicJvmIrTextTestGenerated extends AbstractClassicJvmIrTextTest
runTest("compiler/testData/ir/irText/firProblems/deprecated.kt");
}
@Test
@TestMetadata("elvisOnBackingFieldInGetter.kt")
public void testElvisOnBackingFieldInGetter() throws Exception {
runTest("compiler/testData/ir/irText/firProblems/elvisOnBackingFieldInGetter.kt");
}
@Test
@TestMetadata("emptyWhen.kt")
public void testEmptyWhen() throws Exception {