K2: expand types during smartcasting to prevent redundant intersections
#KT-53184 Fixed
This commit is contained in:
+50
@@ -0,0 +1,50 @@
|
||||
FILE fqName:<root> fileName:/reflectGetOnNullableTypeAlias.kt
|
||||
TYPEALIAS name:PropAlias visibility:private expandedType:kotlin.reflect.KProperty1<T of <root>.PropAlias, kotlin.Any?>?
|
||||
TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?] reified:false
|
||||
FUN name:box visibility:public modality:FINAL <> () returnType:kotlin.String
|
||||
BLOCK_BODY
|
||||
VAR name:backRefProp type:kotlin.reflect.KProperty1<<root>.Foo, kotlin.Any?>? [val]
|
||||
PROPERTY_REFERENCE 'public final bar: kotlin.String [val]' field=null getter='public final fun <get-bar> (): kotlin.String declared in <root>.Foo' setter=null type=kotlin.reflect.KProperty1<<root>.Foo, kotlin.String> 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 backRefProp: kotlin.reflect.KProperty1<<root>.Foo, kotlin.Any?>? [val] declared in <root>.box' type=kotlin.reflect.KProperty1<<root>.Foo, kotlin.Any?>? origin=null
|
||||
arg1: CONST Null type=kotlin.Nothing? value=null
|
||||
then: RETURN type=kotlin.Nothing from='public final fun box (): kotlin.String declared in <root>'
|
||||
TYPE_OP type=kotlin.String origin=CAST typeOperand=kotlin.String
|
||||
CALL 'public abstract fun get (receiver: T of kotlin.reflect.KProperty1): V of kotlin.reflect.KProperty1 declared in kotlin.reflect.KProperty1' type=kotlin.Any? origin=null
|
||||
$this: GET_VAR 'val backRefProp: kotlin.reflect.KProperty1<<root>.Foo, kotlin.Any?>? [val] declared in <root>.box' type=kotlin.reflect.KProperty1<<root>.Foo, kotlin.Any?>? origin=null
|
||||
receiver: CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in <root>.Foo' type=<root>.Foo origin=null
|
||||
RETURN type=kotlin.Nothing from='public final fun box (): kotlin.String declared in <root>'
|
||||
CONST String type=kotlin.String value="FAIL"
|
||||
CLASS CLASS name:Foo modality:FINAL visibility:public superTypes:[kotlin.Any]
|
||||
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Foo
|
||||
CONSTRUCTOR visibility:public <> () returnType:<root>.Foo [primary]
|
||||
BLOCK_BODY
|
||||
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
|
||||
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Foo modality:FINAL visibility:public superTypes:[kotlin.Any]'
|
||||
PROPERTY name:bar visibility:public modality:FINAL [val]
|
||||
FIELD PROPERTY_BACKING_FIELD name:bar type:kotlin.String visibility:private [final]
|
||||
EXPRESSION_BODY
|
||||
CONST String type=kotlin.String value="OK"
|
||||
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-bar> visibility:public modality:FINAL <> ($this:<root>.Foo) returnType:kotlin.String
|
||||
correspondingProperty: PROPERTY name:bar visibility:public modality:FINAL [val]
|
||||
$this: VALUE_PARAMETER name:<this> type:<root>.Foo
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun <get-bar> (): kotlin.String declared in <root>.Foo'
|
||||
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:bar type:kotlin.String visibility:private [final]' type=kotlin.String origin=null
|
||||
receiver: GET_VAR '<this>: <root>.Foo declared in <root>.Foo.<get-bar>' type=<root>.Foo 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 [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
@@ -0,0 +1,21 @@
|
||||
private typealias PropAlias<T : Any?> = KProperty1<T, Any?>?
|
||||
fun box(): String {
|
||||
val backRefProp: KProperty1<Foo, Any?>? = Foo::bar
|
||||
when {
|
||||
EQEQ(arg0 = backRefProp, arg1 = null).not() -> return backRefProp.get(receiver = Foo()) as String
|
||||
}
|
||||
return "FAIL"
|
||||
}
|
||||
|
||||
class Foo {
|
||||
constructor() /* primary */ {
|
||||
super/*Any*/()
|
||||
/* <init>() */
|
||||
|
||||
}
|
||||
|
||||
val bar: String
|
||||
field = "OK"
|
||||
get
|
||||
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
FILE fqName:<root> fileName:/reflectGetOnNullableTypeAlias.kt
|
||||
TYPEALIAS name:PropAlias visibility:private expandedType:kotlin.reflect.KProperty1<T of <root>.PropAlias, kotlin.Any?>?
|
||||
TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?] reified:false
|
||||
FUN name:box visibility:public modality:FINAL <> () returnType:kotlin.String
|
||||
BLOCK_BODY
|
||||
VAR name:backRefProp type:kotlin.reflect.KProperty1<<root>.Foo, kotlin.Any?>?{ <root>.PropAlias<<root>.Foo> } [val]
|
||||
PROPERTY_REFERENCE 'public final bar: kotlin.String [val]' field=null getter='public final fun <get-bar> (): kotlin.String declared in <root>.Foo' setter=null type=kotlin.reflect.KProperty1<<root>.Foo, kotlin.String> 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 backRefProp: kotlin.reflect.KProperty1<<root>.Foo, kotlin.Any?>?{ <root>.PropAlias<<root>.Foo> } [val] declared in <root>.box' type=kotlin.reflect.KProperty1<<root>.Foo, kotlin.Any?>?{ <root>.PropAlias<<root>.Foo> } 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 box (): kotlin.String declared in <root>'
|
||||
TYPE_OP type=kotlin.String origin=CAST typeOperand=kotlin.String
|
||||
CALL 'public abstract fun get (receiver: T of kotlin.reflect.KProperty1): V of kotlin.reflect.KProperty1 declared in kotlin.reflect.KProperty1' type=kotlin.Any? origin=null
|
||||
$this: GET_VAR 'val backRefProp: kotlin.reflect.KProperty1<<root>.Foo, kotlin.Any?>?{ <root>.PropAlias<<root>.Foo> } [val] declared in <root>.box' type=kotlin.reflect.KProperty1<<root>.Foo, kotlin.Any?>?{ <root>.PropAlias<<root>.Foo> } origin=null
|
||||
receiver: CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in <root>.Foo' type=<root>.Foo origin=null
|
||||
RETURN type=kotlin.Nothing from='public final fun box (): kotlin.String declared in <root>'
|
||||
CONST String type=kotlin.String value="FAIL"
|
||||
CLASS CLASS name:Foo modality:FINAL visibility:public superTypes:[kotlin.Any]
|
||||
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Foo
|
||||
CONSTRUCTOR visibility:public <> () returnType:<root>.Foo [primary]
|
||||
BLOCK_BODY
|
||||
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
|
||||
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Foo modality:FINAL visibility:public superTypes:[kotlin.Any]'
|
||||
PROPERTY name:bar visibility:public modality:FINAL [val]
|
||||
FIELD PROPERTY_BACKING_FIELD name:bar type:kotlin.String visibility:private [final]
|
||||
EXPRESSION_BODY
|
||||
CONST String type=kotlin.String value="OK"
|
||||
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-bar> visibility:public modality:FINAL <> ($this:<root>.Foo) returnType:kotlin.String
|
||||
correspondingProperty: PROPERTY name:bar visibility:public modality:FINAL [val]
|
||||
$this: VALUE_PARAMETER name:<this> type:<root>.Foo
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun <get-bar> (): kotlin.String declared in <root>.Foo'
|
||||
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:bar type:kotlin.String visibility:private [final]' type=kotlin.String origin=null
|
||||
receiver: GET_VAR '<this>: <root>.Foo declared in <root>.Foo.<get-bar>' type=<root>.Foo 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 [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
|
||||
@@ -0,0 +1,18 @@
|
||||
// SKIP_KLIB_TEST
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.reflect.KProperty1
|
||||
|
||||
private typealias PropAlias<T> = KProperty1<T, Any?>?
|
||||
|
||||
fun box(): String {
|
||||
val backRefProp: PropAlias<Foo> = Foo::bar
|
||||
if (backRefProp != null) {
|
||||
return backRefProp.get(Foo()) as String
|
||||
}
|
||||
return "FAIL"
|
||||
}
|
||||
|
||||
class Foo {
|
||||
val bar: String = "OK"
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
private typealias PropAlias<T : Any?> = KProperty1<T, Any?>?
|
||||
fun box(): String {
|
||||
val backRefProp: KProperty1<Foo, Any?>? = Foo::bar
|
||||
when {
|
||||
EQEQ(arg0 = backRefProp, arg1 = null).not() -> { // BLOCK
|
||||
return backRefProp.get(receiver = Foo()) as String
|
||||
}
|
||||
}
|
||||
return "FAIL"
|
||||
}
|
||||
|
||||
class Foo {
|
||||
constructor() /* primary */ {
|
||||
super/*Any*/()
|
||||
/* <init>() */
|
||||
|
||||
}
|
||||
|
||||
val bar: String
|
||||
field = "OK"
|
||||
get
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user