[FIR] fix false negative MUST_BE_INITIALIZED for deferred init + custom setter case

^KT-58346 Fixed
Review: https://jetbrains.team/p/kt/reviews/9967

BTW this commit accidentaly and partially fixes KT-57553 for K2, because
of a cleaner K2 architecture. I will unify MUST_BE_INITIALIZED behaviour
in K1 and K2 in the next commits
This commit is contained in:
Nikita Bobko
2023-05-15 11:59:40 +02:00
parent 151144bbed
commit d9d4dee582
17 changed files with 87 additions and 450 deletions
-80
View File
@@ -155,83 +155,3 @@ FILE fqName:<root> fileName:/initVar.kt
overridden:
public open fun toString (): kotlin.String declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
CLASS CLASS name:TestInitVarWithCustomSetterWithExplicitCtor modality:FINAL visibility:public superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.TestInitVarWithCustomSetterWithExplicitCtor
PROPERTY name:x visibility:public modality:FINAL [var]
FIELD PROPERTY_BACKING_FIELD name:x type:kotlin.Int visibility:private
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-x> visibility:public modality:FINAL <> ($this:<root>.TestInitVarWithCustomSetterWithExplicitCtor) returnType:kotlin.Int
correspondingProperty: PROPERTY name:x visibility:public modality:FINAL [var]
$this: VALUE_PARAMETER name:<this> type:<root>.TestInitVarWithCustomSetterWithExplicitCtor
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun <get-x> (): kotlin.Int declared in <root>.TestInitVarWithCustomSetterWithExplicitCtor'
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:x type:kotlin.Int visibility:private' type=kotlin.Int origin=null
receiver: GET_VAR '<this>: <root>.TestInitVarWithCustomSetterWithExplicitCtor declared in <root>.TestInitVarWithCustomSetterWithExplicitCtor.<get-x>' type=<root>.TestInitVarWithCustomSetterWithExplicitCtor origin=null
FUN name:<set-x> visibility:public modality:FINAL <> ($this:<root>.TestInitVarWithCustomSetterWithExplicitCtor, value:kotlin.Int) returnType:kotlin.Unit
correspondingProperty: PROPERTY name:x visibility:public modality:FINAL [var]
$this: VALUE_PARAMETER name:<this> type:<root>.TestInitVarWithCustomSetterWithExplicitCtor
VALUE_PARAMETER name:value index:0 type:kotlin.Int
BLOCK_BODY
SET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:x type:kotlin.Int visibility:private' type=kotlin.Unit origin=EQ
receiver: GET_VAR '<this>: <root>.TestInitVarWithCustomSetterWithExplicitCtor declared in <root>.TestInitVarWithCustomSetterWithExplicitCtor.<set-x>' type=<root>.TestInitVarWithCustomSetterWithExplicitCtor origin=null
value: GET_VAR 'value: kotlin.Int declared in <root>.TestInitVarWithCustomSetterWithExplicitCtor.<set-x>' type=kotlin.Int origin=null
ANONYMOUS_INITIALIZER isStatic=false
BLOCK_BODY
CALL 'public final fun <set-x> (value: kotlin.Int): kotlin.Unit declared in <root>.TestInitVarWithCustomSetterWithExplicitCtor' type=kotlin.Unit origin=EQ
$this: GET_VAR '<this>: <root>.TestInitVarWithCustomSetterWithExplicitCtor declared in <root>.TestInitVarWithCustomSetterWithExplicitCtor' type=<root>.TestInitVarWithCustomSetterWithExplicitCtor origin=null
value: CONST Int type=kotlin.Int value=0
CONSTRUCTOR visibility:public <> () returnType:<root>.TestInitVarWithCustomSetterWithExplicitCtor
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:TestInitVarWithCustomSetterWithExplicitCtor 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 [operator] 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:TestInitVarWithCustomSetterInCtor modality:FINAL visibility:public superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.TestInitVarWithCustomSetterInCtor
PROPERTY name:x visibility:public modality:FINAL [var]
FIELD PROPERTY_BACKING_FIELD name:x type:kotlin.Int visibility:private
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-x> visibility:public modality:FINAL <> ($this:<root>.TestInitVarWithCustomSetterInCtor) returnType:kotlin.Int
correspondingProperty: PROPERTY name:x visibility:public modality:FINAL [var]
$this: VALUE_PARAMETER name:<this> type:<root>.TestInitVarWithCustomSetterInCtor
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun <get-x> (): kotlin.Int declared in <root>.TestInitVarWithCustomSetterInCtor'
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:x type:kotlin.Int visibility:private' type=kotlin.Int origin=null
receiver: GET_VAR '<this>: <root>.TestInitVarWithCustomSetterInCtor declared in <root>.TestInitVarWithCustomSetterInCtor.<get-x>' type=<root>.TestInitVarWithCustomSetterInCtor origin=null
FUN name:<set-x> visibility:public modality:FINAL <> ($this:<root>.TestInitVarWithCustomSetterInCtor, value:kotlin.Int) returnType:kotlin.Unit
correspondingProperty: PROPERTY name:x visibility:public modality:FINAL [var]
$this: VALUE_PARAMETER name:<this> type:<root>.TestInitVarWithCustomSetterInCtor
VALUE_PARAMETER name:value index:0 type:kotlin.Int
BLOCK_BODY
SET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:x type:kotlin.Int visibility:private' type=kotlin.Unit origin=EQ
receiver: GET_VAR '<this>: <root>.TestInitVarWithCustomSetterInCtor declared in <root>.TestInitVarWithCustomSetterInCtor.<set-x>' type=<root>.TestInitVarWithCustomSetterInCtor origin=null
value: GET_VAR 'value: kotlin.Int declared in <root>.TestInitVarWithCustomSetterInCtor.<set-x>' type=kotlin.Int origin=null
CONSTRUCTOR visibility:public <> () returnType:<root>.TestInitVarWithCustomSetterInCtor
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:TestInitVarWithCustomSetterInCtor modality:FINAL visibility:public superTypes:[kotlin.Any]'
CALL 'public final fun <set-x> (value: kotlin.Int): kotlin.Unit declared in <root>.TestInitVarWithCustomSetterInCtor' type=kotlin.Unit origin=EQ
$this: GET_VAR '<this>: <root>.TestInitVarWithCustomSetterInCtor declared in <root>.TestInitVarWithCustomSetterInCtor' type=<root>.TestInitVarWithCustomSetterInCtor origin=null
value: CONST Int type=kotlin.Int value=42
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 [operator] 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
-21
View File
@@ -16,24 +16,3 @@ class TestInitVarWithCustomSetter {
var x = 0
set(value) { field = value }
}
class TestInitVarWithCustomSetterWithExplicitCtor {
var x: Int
set(value) { field = value }
init {
x = 0
}
constructor()
}
class TestInitVarWithCustomSetterInCtor {
var x: Int set(value) {
field = value
}
constructor() {
x = 42
}
}
-34
View File
@@ -59,37 +59,3 @@ class TestInitVarWithCustomSetter {
}
class TestInitVarWithCustomSetterWithExplicitCtor {
var x: Int
get
set(value: Int) {
<this>.#x = value
}
init {
<this>.<set-x>(value = 0)
}
constructor() {
super/*Any*/()
/* <init>() */
}
}
class TestInitVarWithCustomSetterInCtor {
var x: Int
get
set(value: Int) {
<this>.#x = value
}
constructor() {
super/*Any*/()
/* <init>() */
<this>.<set-x>(value = 42)
}
}
-54
View File
@@ -106,57 +106,3 @@ class TestInitVarWithCustomSetter {
}
// CHECK:
// Mangled name: TestInitVarWithCustomSetterInCtor
// Public signature: /TestInitVarWithCustomSetterInCtor|null[0]
class TestInitVarWithCustomSetterInCtor {
// CHECK:
// Mangled name: TestInitVarWithCustomSetterInCtor{}x
// Public signature: /TestInitVarWithCustomSetterInCtor.x|-8060530855978347579[0]
var x: Int
// CHECK JVM_IR:
// Mangled name: TestInitVarWithCustomSetterInCtor#<get-x>(){}kotlin.Int
// Public signature: /TestInitVarWithCustomSetterInCtor.x.<get-x>|4966956098150895696[0]
// CHECK JS_IR NATIVE:
// Mangled name: TestInitVarWithCustomSetterInCtor#<get-x>(){}
// Public signature: /TestInitVarWithCustomSetterInCtor.x.<get-x>|1482705010654679335[0]
get
// CHECK:
// Mangled name: TestInitVarWithCustomSetterInCtor#<set-x>(kotlin.Int){}
// Public signature: /TestInitVarWithCustomSetterInCtor.x.<set-x>|-740209739415615559[0]
set(value: Int): Unit
// CHECK:
// Mangled name: TestInitVarWithCustomSetterInCtor#<init>(){}
// Public signature: /TestInitVarWithCustomSetterInCtor.<init>|-5645683436151566731[0]
constructor()
}
// CHECK:
// Mangled name: TestInitVarWithCustomSetterWithExplicitCtor
// Public signature: /TestInitVarWithCustomSetterWithExplicitCtor|null[0]
class TestInitVarWithCustomSetterWithExplicitCtor {
// CHECK:
// Mangled name: TestInitVarWithCustomSetterWithExplicitCtor{}x
// Public signature: /TestInitVarWithCustomSetterWithExplicitCtor.x|-8060530855978347579[0]
var x: Int
// CHECK JVM_IR:
// Mangled name: TestInitVarWithCustomSetterWithExplicitCtor#<get-x>(){}kotlin.Int
// Public signature: /TestInitVarWithCustomSetterWithExplicitCtor.x.<get-x>|4966956098150895696[0]
// CHECK JS_IR NATIVE:
// Mangled name: TestInitVarWithCustomSetterWithExplicitCtor#<get-x>(){}
// Public signature: /TestInitVarWithCustomSetterWithExplicitCtor.x.<get-x>|1482705010654679335[0]
get
// CHECK:
// Mangled name: TestInitVarWithCustomSetterWithExplicitCtor#<set-x>(kotlin.Int){}
// Public signature: /TestInitVarWithCustomSetterWithExplicitCtor.x.<set-x>|-740209739415615559[0]
set(value: Int): Unit
// CHECK:
// Mangled name: TestInitVarWithCustomSetterWithExplicitCtor#<init>(){}
// Public signature: /TestInitVarWithCustomSetterWithExplicitCtor.<init>|-5645683436151566731[0]
constructor()
}