[FIR2IR] Don't insert not-needed upcasts for smartcasted expressions
Related to KT-63257
This commit is contained in:
committed by
Space Team
parent
aa1a997f8a
commit
c70a6425f5
+13
-2
@@ -276,9 +276,16 @@ class Fir2IrImplicitCastInserter(
|
||||
override fun visitSmartCastExpression(smartCastExpression: FirSmartCastExpression, data: IrElement): IrElement {
|
||||
// We don't want an implicit cast to Nothing?. This expression just encompasses nullability after null check.
|
||||
return if (smartCastExpression.isStable && smartCastExpression.smartcastTypeWithoutNullableNothing == null) {
|
||||
implicitCastOrExpression(data as IrExpression, smartCastExpression.resolvedType)
|
||||
val smartcastedType = smartCastExpression.resolvedType
|
||||
val approximatedType = smartcastedType.approximateForIrOrNull()
|
||||
if (approximatedType != null) {
|
||||
if (smartCastExpression.originalExpression.resolvedType.isSubtypeOf(approximatedType, session)) {
|
||||
return data
|
||||
}
|
||||
}
|
||||
implicitCastOrExpression(data as IrExpression, approximatedType ?: smartcastedType)
|
||||
} else {
|
||||
data as IrExpression
|
||||
data
|
||||
}
|
||||
}
|
||||
|
||||
@@ -410,4 +417,8 @@ class Fir2IrImplicitCastInserter(
|
||||
return lowerBound.isMarkedNullable != upperBound.isMarkedNullable
|
||||
}
|
||||
}
|
||||
|
||||
private fun ConeKotlinType.approximateForIrOrNull(): ConeKotlinType? {
|
||||
return session.typeApproximator.approximateToSuperType(this, TypeApproximatorConfiguration.FrontendToBackendTypesApproximation)
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -1280,10 +1280,11 @@ class CallAndReferenceGenerator(
|
||||
symbol.fir.receiverParameter?.typeRef?.let { receiverType ->
|
||||
with(visitor.implicitCastInserter) {
|
||||
val extensionReceiver = qualifiedAccess.extensionReceiver!!
|
||||
val substitutor = qualifiedAccess.buildSubstitutorByCalledCallable()
|
||||
it.cast(
|
||||
extensionReceiver,
|
||||
extensionReceiver.resolvedType,
|
||||
receiverType.coneType,
|
||||
substitutor.substituteOrSelf(receiverType.coneType),
|
||||
)
|
||||
}
|
||||
} ?: it
|
||||
|
||||
+1
-2
@@ -105,8 +105,7 @@ FILE fqName:<root> fileName:/test.kt
|
||||
CALL 'public abstract fun <get-simpleName> (): kotlin.String? declared in kotlin.reflect.KClass' type=kotlin.String? origin=GET_PROPERTY
|
||||
$this: CALL 'public final fun <get-annotationClass> <T> (): kotlin.reflect.KClass<out T of kotlin.jvm.<get-annotationClass>> declared in kotlin.jvm' type=kotlin.reflect.KClass<out @[FlexibleNullability] kotlin.Annotation?> origin=GET_PROPERTY
|
||||
<T>: @[FlexibleNullability] kotlin.Annotation?
|
||||
$receiver: TYPE_OP type=kotlin.Annotation origin=IMPLICIT_NOTNULL typeOperand=kotlin.Annotation
|
||||
GET_VAR 'it: @[FlexibleNullability] kotlin.Annotation? declared in <root>.box.<anonymous>' type=@[FlexibleNullability] kotlin.Annotation? origin=null
|
||||
$receiver: GET_VAR 'it: @[FlexibleNullability] kotlin.Annotation? declared in <root>.box.<anonymous>' type=@[FlexibleNullability] kotlin.Annotation? origin=null
|
||||
WHEN type=kotlin.String 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
|
||||
|
||||
+1
-2
@@ -264,8 +264,7 @@ FILE fqName:<root> fileName:/targetOnPrimaryCtorParameter.kt
|
||||
CALL 'public abstract fun <get-simpleName> (): kotlin.String? declared in kotlin.reflect.KClass' type=kotlin.String? origin=GET_PROPERTY
|
||||
$this: CALL 'public final fun <get-annotationClass> <T> (): kotlin.reflect.KClass<out T of kotlin.jvm.<get-annotationClass>> declared in kotlin.jvm' type=kotlin.reflect.KClass<out @[FlexibleNullability] kotlin.Annotation?> origin=GET_PROPERTY
|
||||
<T>: @[FlexibleNullability] kotlin.Annotation?
|
||||
$receiver: TYPE_OP type=kotlin.Annotation origin=IMPLICIT_NOTNULL typeOperand=kotlin.Annotation
|
||||
GET_VAR 'it: @[FlexibleNullability] kotlin.Annotation? declared in <root>.box.<anonymous>' type=@[FlexibleNullability] kotlin.Annotation? origin=null
|
||||
$receiver: GET_VAR 'it: @[FlexibleNullability] kotlin.Annotation? declared in <root>.box.<anonymous>' type=@[FlexibleNullability] kotlin.Annotation? origin=null
|
||||
WHEN type=kotlin.String 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
|
||||
|
||||
@@ -47,8 +47,7 @@ FILE fqName:<root> fileName:/bangbang.kt
|
||||
then: TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit
|
||||
CALL 'public final fun CHECK_NOT_NULL <T0> (arg0: T0 of kotlin.internal.ir.CHECK_NOT_NULL?): {T0 of kotlin.internal.ir.CHECK_NOT_NULL & Any} declared in kotlin.internal.ir' type=kotlin.Any origin=EXCLEXCL
|
||||
<T0>: kotlin.Any
|
||||
arg0: TYPE_OP type=kotlin.Any? origin=IMPLICIT_CAST typeOperand=kotlin.Any?
|
||||
GET_VAR 'a: X of <root>.test4 declared in <root>.test4' type=X of <root>.test4 origin=null
|
||||
arg0: GET_VAR 'a: X of <root>.test4 declared in <root>.test4' type=X of <root>.test4 origin=null
|
||||
WHEN type=kotlin.Unit origin=IF
|
||||
BRANCH
|
||||
if: TYPE_OP type=kotlin.Boolean origin=INSTANCEOF typeOperand=kotlin.String?
|
||||
|
||||
@@ -21,7 +21,7 @@ fun useString(s: String) {
|
||||
|
||||
fun <X : Any?> test4(a: X) {
|
||||
when {
|
||||
a is String? -> CHECK_NOT_NULL<Any>(arg0 = a /*as Any? */) /*~> Unit */
|
||||
a is String? -> CHECK_NOT_NULL<Any>(arg0 = a) /*~> Unit */
|
||||
}
|
||||
when {
|
||||
a is String? -> useString(s = CHECK_NOT_NULL<Any>(arg0 = a /*as Any */))
|
||||
|
||||
Vendored
+1
-2
@@ -180,8 +180,7 @@ FILE fqName:<root> fileName:/caoWithAdaptationForSam.kt
|
||||
VAR IR_TEMPORARY_VARIABLE name:tmp_6 type:<root>.A [val]
|
||||
GET_OBJECT 'CLASS OBJECT name:A modality:FINAL visibility:public superTypes:[kotlin.Any]' type=<root>.A
|
||||
VAR IR_TEMPORARY_VARIABLE name:tmp_7 type:kotlin.Any [val]
|
||||
TYPE_OP type=kotlin.Any origin=IMPLICIT_CAST typeOperand=kotlin.Any
|
||||
GET_VAR 'fn: kotlin.Function1<kotlin.Int, kotlin.Unit> declared in <root>.test4' type=kotlin.Function1<kotlin.Int, kotlin.Unit> origin=null
|
||||
GET_VAR 'fn: kotlin.Function1<kotlin.Int, kotlin.Unit> declared in <root>.test4' type=kotlin.Function1<kotlin.Int, kotlin.Unit> origin=null
|
||||
CALL 'public final fun set (i: <root>.IFoo, newValue: kotlin.Int): kotlin.Unit declared in <root>' type=kotlin.Unit origin=null
|
||||
$receiver: GET_VAR 'val tmp_6: <root>.A declared in <root>.test4' type=<root>.A origin=null
|
||||
i: GET_VAR 'val tmp_7: kotlin.Any declared in <root>.test4' type=kotlin.Any origin=null
|
||||
|
||||
Vendored
+1
-1
@@ -84,7 +84,7 @@ fun test4(fn: Function1<Int, Unit>) {
|
||||
fn is IFoo -> { // BLOCK
|
||||
{ // BLOCK
|
||||
val tmp_6: A = A
|
||||
val tmp_7: Any = fn /*as Any */
|
||||
val tmp_7: Any = fn
|
||||
tmp_6.set(i = tmp_7, newValue = tmp_6.get(i = tmp_7).plus(other = 1))
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+7
-14
@@ -44,8 +44,7 @@ FILE fqName:<root> fileName:/samConversionsWithSmartCasts.kt
|
||||
GET_VAR 'a: kotlin.Function0<kotlin.Unit> declared in <root>.test1' type=kotlin.Function0<kotlin.Unit> origin=null
|
||||
then: BLOCK type=kotlin.Unit origin=null
|
||||
CALL 'public final fun run1 (r: <root>.KRunnable): kotlin.Unit declared in <root>' type=kotlin.Unit origin=null
|
||||
r: TYPE_OP type=kotlin.Any origin=IMPLICIT_CAST typeOperand=kotlin.Any
|
||||
GET_VAR 'a: kotlin.Function0<kotlin.Unit> declared in <root>.test1' type=kotlin.Function0<kotlin.Unit> origin=null
|
||||
r: GET_VAR 'a: kotlin.Function0<kotlin.Unit> declared in <root>.test1' type=kotlin.Function0<kotlin.Unit> origin=null
|
||||
FUN name:test2 visibility:public modality:FINAL <> (a:<root>.KRunnable) returnType:kotlin.Unit
|
||||
VALUE_PARAMETER name:a index:0 type:<root>.KRunnable
|
||||
BLOCK_BODY
|
||||
@@ -53,8 +52,7 @@ FILE fqName:<root> fileName:/samConversionsWithSmartCasts.kt
|
||||
TYPE_OP type=kotlin.Function0<kotlin.Unit> origin=CAST typeOperand=kotlin.Function0<kotlin.Unit>
|
||||
GET_VAR 'a: <root>.KRunnable declared in <root>.test2' type=<root>.KRunnable origin=null
|
||||
CALL 'public final fun run1 (r: <root>.KRunnable): kotlin.Unit declared in <root>' type=kotlin.Unit origin=null
|
||||
r: TYPE_OP type=kotlin.Any origin=IMPLICIT_CAST typeOperand=kotlin.Any
|
||||
GET_VAR 'a: <root>.KRunnable declared in <root>.test2' type=<root>.KRunnable origin=null
|
||||
r: GET_VAR 'a: <root>.KRunnable declared in <root>.test2' type=<root>.KRunnable origin=null
|
||||
FUN name:test3 visibility:public modality:FINAL <> (a:kotlin.Function0<kotlin.Unit>) returnType:kotlin.Unit
|
||||
VALUE_PARAMETER name:a index:0 type:kotlin.Function0<kotlin.Unit>
|
||||
BLOCK_BODY
|
||||
@@ -64,10 +62,8 @@ FILE fqName:<root> fileName:/samConversionsWithSmartCasts.kt
|
||||
GET_VAR 'a: kotlin.Function0<kotlin.Unit> declared in <root>.test3' type=kotlin.Function0<kotlin.Unit> origin=null
|
||||
then: BLOCK type=kotlin.Unit origin=null
|
||||
CALL 'public final fun run2 (r1: <root>.KRunnable, r2: <root>.KRunnable): kotlin.Unit declared in <root>' type=kotlin.Unit origin=null
|
||||
r1: TYPE_OP type=kotlin.Any origin=IMPLICIT_CAST typeOperand=kotlin.Any
|
||||
GET_VAR 'a: kotlin.Function0<kotlin.Unit> declared in <root>.test3' type=kotlin.Function0<kotlin.Unit> origin=null
|
||||
r2: TYPE_OP type=kotlin.Any origin=IMPLICIT_CAST typeOperand=kotlin.Any
|
||||
GET_VAR 'a: kotlin.Function0<kotlin.Unit> declared in <root>.test3' type=kotlin.Function0<kotlin.Unit> origin=null
|
||||
r1: GET_VAR 'a: kotlin.Function0<kotlin.Unit> declared in <root>.test3' type=kotlin.Function0<kotlin.Unit> origin=null
|
||||
r2: GET_VAR 'a: kotlin.Function0<kotlin.Unit> declared in <root>.test3' type=kotlin.Function0<kotlin.Unit> origin=null
|
||||
FUN name:test4 visibility:public modality:FINAL <> (a:kotlin.Function0<kotlin.Unit>, b:kotlin.Function0<kotlin.Unit>) returnType:kotlin.Unit
|
||||
VALUE_PARAMETER name:a index:0 type:kotlin.Function0<kotlin.Unit>
|
||||
VALUE_PARAMETER name:b index:1 type:kotlin.Function0<kotlin.Unit>
|
||||
@@ -78,8 +74,7 @@ FILE fqName:<root> fileName:/samConversionsWithSmartCasts.kt
|
||||
GET_VAR 'a: kotlin.Function0<kotlin.Unit> declared in <root>.test4' type=kotlin.Function0<kotlin.Unit> origin=null
|
||||
then: BLOCK type=kotlin.Unit origin=null
|
||||
CALL 'public final fun run2 (r1: <root>.KRunnable, r2: <root>.KRunnable): kotlin.Unit declared in <root>' type=kotlin.Unit origin=null
|
||||
r1: TYPE_OP type=kotlin.Any origin=IMPLICIT_CAST typeOperand=kotlin.Any
|
||||
GET_VAR 'a: kotlin.Function0<kotlin.Unit> declared in <root>.test4' type=kotlin.Function0<kotlin.Unit> origin=null
|
||||
r1: GET_VAR 'a: kotlin.Function0<kotlin.Unit> declared in <root>.test4' type=kotlin.Function0<kotlin.Unit> origin=null
|
||||
r2: TYPE_OP type=<root>.KRunnable origin=SAM_CONVERSION typeOperand=<root>.KRunnable
|
||||
GET_VAR 'b: kotlin.Function0<kotlin.Unit> declared in <root>.test4' type=kotlin.Function0<kotlin.Unit> origin=null
|
||||
FUN name:test5 visibility:public modality:FINAL <> (a:kotlin.Any) returnType:kotlin.Unit
|
||||
@@ -125,8 +120,7 @@ FILE fqName:<root> fileName:/samConversionsWithSmartCasts.kt
|
||||
GET_VAR 'a: kotlin.Function1<kotlin.Int, kotlin.Int> declared in <root>.test7' type=kotlin.Function1<kotlin.Int, kotlin.Int> origin=null
|
||||
CALL 'public final fun run1 (r: <root>.KRunnable): kotlin.Unit declared in <root>' type=kotlin.Unit origin=null
|
||||
r: TYPE_OP type=<root>.KRunnable origin=SAM_CONVERSION typeOperand=<root>.KRunnable
|
||||
TYPE_OP type=kotlin.Function<kotlin.Any> origin=IMPLICIT_CAST typeOperand=kotlin.Function<kotlin.Any>
|
||||
GET_VAR 'a: kotlin.Function1<kotlin.Int, kotlin.Int> declared in <root>.test7' type=kotlin.Function1<kotlin.Int, kotlin.Int> origin=null
|
||||
GET_VAR 'a: kotlin.Function1<kotlin.Int, kotlin.Int> declared in <root>.test7' type=kotlin.Function1<kotlin.Int, kotlin.Int> origin=null
|
||||
FUN name:test7a visibility:public modality:FINAL <T> (a:T of <root>.test7a) returnType:kotlin.Unit
|
||||
TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Function1<kotlin.Int, kotlin.Int>] reified:false
|
||||
VALUE_PARAMETER name:a index:0 type:T of <root>.test7a
|
||||
@@ -136,8 +130,7 @@ FILE fqName:<root> fileName:/samConversionsWithSmartCasts.kt
|
||||
GET_VAR 'a: T of <root>.test7a declared in <root>.test7a' type=T of <root>.test7a origin=null
|
||||
CALL 'public final fun run1 (r: <root>.KRunnable): kotlin.Unit declared in <root>' type=kotlin.Unit origin=null
|
||||
r: TYPE_OP type=<root>.KRunnable origin=SAM_CONVERSION typeOperand=<root>.KRunnable
|
||||
TYPE_OP type=kotlin.Function<kotlin.Any> origin=IMPLICIT_CAST typeOperand=kotlin.Function<kotlin.Any>
|
||||
GET_VAR 'a: T of <root>.test7a declared in <root>.test7a' type=T of <root>.test7a origin=null
|
||||
GET_VAR 'a: T of <root>.test7a declared in <root>.test7a' type=T of <root>.test7a origin=null
|
||||
FUN name:test7b visibility:public modality:FINAL <T> (a:T of <root>.test7b) returnType:kotlin.Unit
|
||||
TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Function1<kotlin.Int, kotlin.Unit>; kotlin.Function0<kotlin.Unit>] reified:false
|
||||
VALUE_PARAMETER name:a index:0 type:T of <root>.test7b
|
||||
|
||||
Vendored
+6
-6
@@ -20,20 +20,20 @@ fun <T> test0(a: T) where T : KRunnable, T : Function0<Unit> {
|
||||
fun test1(a: Function0<Unit>) {
|
||||
when {
|
||||
a is KRunnable -> { // BLOCK
|
||||
run1(r = a /*as Any */)
|
||||
run1(r = a)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun test2(a: KRunnable) {
|
||||
a as Function0<Unit> /*~> Unit */
|
||||
run1(r = a /*as Any */)
|
||||
run1(r = a)
|
||||
}
|
||||
|
||||
fun test3(a: Function0<Unit>) {
|
||||
when {
|
||||
a is KRunnable -> { // BLOCK
|
||||
run2(r1 = a /*as Any */, r2 = a /*as Any */)
|
||||
run2(r1 = a, r2 = a)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -41,7 +41,7 @@ fun test3(a: Function0<Unit>) {
|
||||
fun test4(a: Function0<Unit>, b: Function0<Unit>) {
|
||||
when {
|
||||
a is KRunnable -> { // BLOCK
|
||||
run2(r1 = a /*as Any */, r2 = b /*-> KRunnable */)
|
||||
run2(r1 = a, r2 = b /*-> KRunnable */)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -70,12 +70,12 @@ fun test6(a: Any) {
|
||||
|
||||
fun test7(a: Function1<Int, Int>) {
|
||||
a as Function0<Unit> /*~> Unit */
|
||||
run1(r = a /*as Function<Any> */ /*-> KRunnable */)
|
||||
run1(r = a /*-> KRunnable */)
|
||||
}
|
||||
|
||||
fun <T : Function1<Int, Int>> test7a(a: T) {
|
||||
a as Function0<Unit> /*~> Unit */
|
||||
run1(r = a /*as Function<Any> */ /*-> KRunnable */)
|
||||
run1(r = a /*-> KRunnable */)
|
||||
}
|
||||
|
||||
fun <T> test7b(a: T) where T : Function1<Int, Unit>, T : Function0<Unit> {
|
||||
|
||||
+1
-2
@@ -40,8 +40,7 @@ FILE fqName:<root> fileName:/implicitCastToTypeParameter.kt
|
||||
BRANCH
|
||||
if: TYPE_OP type=kotlin.Boolean origin=INSTANCEOF typeOperand=T of <root>.<get-asT>
|
||||
GET_VAR '<this>: <root>.Foo<T of <root>.<get-asT>> declared in <root>.<get-asT>' type=<root>.Foo<T of <root>.<get-asT>> origin=null
|
||||
then: TYPE_OP type=kotlin.Any origin=IMPLICIT_CAST typeOperand=kotlin.Any
|
||||
GET_VAR '<this>: <root>.Foo<T of <root>.<get-asT>> declared in <root>.<get-asT>' type=<root>.Foo<T of <root>.<get-asT>> origin=null
|
||||
then: GET_VAR '<this>: <root>.Foo<T of <root>.<get-asT>> declared in <root>.<get-asT>' type=<root>.Foo<T of <root>.<get-asT>> origin=null
|
||||
BRANCH
|
||||
if: CONST Boolean type=kotlin.Boolean value=true
|
||||
then: CONST Null type=kotlin.Nothing? value=null
|
||||
|
||||
+2
-1
@@ -12,7 +12,7 @@ interface Foo<T : Any?> {
|
||||
val <reified T : Any> Foo<T>.asT: T?
|
||||
inline get(): T? {
|
||||
return when {
|
||||
<this> is T -> <this> /*as Any */
|
||||
<this> is T -> <this>
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
@@ -33,3 +33,4 @@ class Bar<T : Any?> {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
+6
-12
@@ -8,8 +8,7 @@ FILE fqName:<root> fileName:/samConversionsWithSmartCasts.kt
|
||||
GET_VAR 'a: kotlin.Function0<kotlin.Unit> declared in <root>.test1' type=kotlin.Function0<kotlin.Unit> origin=null
|
||||
then: BLOCK type=kotlin.Unit origin=null
|
||||
CALL 'public open fun runStatic (r: @[FlexibleNullability] java.lang.Runnable?): kotlin.Unit declared in <root>.J' type=kotlin.Unit origin=null
|
||||
r: TYPE_OP type=kotlin.Any origin=IMPLICIT_CAST typeOperand=kotlin.Any
|
||||
GET_VAR 'a: kotlin.Function0<kotlin.Unit> declared in <root>.test1' type=kotlin.Function0<kotlin.Unit> origin=null
|
||||
r: GET_VAR 'a: kotlin.Function0<kotlin.Unit> declared in <root>.test1' type=kotlin.Function0<kotlin.Unit> origin=null
|
||||
FUN name:test2 visibility:public modality:FINAL <> (a:kotlin.Function0<kotlin.Unit>) returnType:kotlin.Unit
|
||||
VALUE_PARAMETER name:a index:0 type:kotlin.Function0<kotlin.Unit>
|
||||
BLOCK_BODY
|
||||
@@ -20,8 +19,7 @@ FILE fqName:<root> fileName:/samConversionsWithSmartCasts.kt
|
||||
then: BLOCK type=kotlin.Unit origin=null
|
||||
CALL 'public open fun run1 (r: @[FlexibleNullability] java.lang.Runnable?): kotlin.Unit declared in <root>.J' type=kotlin.Unit origin=null
|
||||
$this: CONSTRUCTOR_CALL 'public constructor <init> () declared in <root>.J' type=<root>.J origin=null
|
||||
r: TYPE_OP type=kotlin.Any origin=IMPLICIT_CAST typeOperand=kotlin.Any
|
||||
GET_VAR 'a: kotlin.Function0<kotlin.Unit> declared in <root>.test2' type=kotlin.Function0<kotlin.Unit> origin=null
|
||||
r: GET_VAR 'a: kotlin.Function0<kotlin.Unit> declared in <root>.test2' type=kotlin.Function0<kotlin.Unit> origin=null
|
||||
FUN name:test3 visibility:public modality:FINAL <> (a:kotlin.Function0<kotlin.Unit>) returnType:kotlin.Unit
|
||||
VALUE_PARAMETER name:a index:0 type:kotlin.Function0<kotlin.Unit>
|
||||
BLOCK_BODY
|
||||
@@ -32,10 +30,8 @@ FILE fqName:<root> fileName:/samConversionsWithSmartCasts.kt
|
||||
then: BLOCK type=kotlin.Unit origin=null
|
||||
CALL 'public open fun run2 (r1: @[FlexibleNullability] java.lang.Runnable?, r2: @[FlexibleNullability] java.lang.Runnable?): kotlin.Unit declared in <root>.J' type=kotlin.Unit origin=null
|
||||
$this: CONSTRUCTOR_CALL 'public constructor <init> () declared in <root>.J' type=<root>.J origin=null
|
||||
r1: TYPE_OP type=kotlin.Any origin=IMPLICIT_CAST typeOperand=kotlin.Any
|
||||
GET_VAR 'a: kotlin.Function0<kotlin.Unit> declared in <root>.test3' type=kotlin.Function0<kotlin.Unit> origin=null
|
||||
r2: TYPE_OP type=kotlin.Any origin=IMPLICIT_CAST typeOperand=kotlin.Any
|
||||
GET_VAR 'a: kotlin.Function0<kotlin.Unit> declared in <root>.test3' type=kotlin.Function0<kotlin.Unit> origin=null
|
||||
r1: GET_VAR 'a: kotlin.Function0<kotlin.Unit> declared in <root>.test3' type=kotlin.Function0<kotlin.Unit> origin=null
|
||||
r2: GET_VAR 'a: kotlin.Function0<kotlin.Unit> declared in <root>.test3' type=kotlin.Function0<kotlin.Unit> origin=null
|
||||
FUN name:test4 visibility:public modality:FINAL <> (a:kotlin.Function0<kotlin.Unit>, b:kotlin.Function0<kotlin.Unit>) returnType:kotlin.Unit
|
||||
VALUE_PARAMETER name:a index:0 type:kotlin.Function0<kotlin.Unit>
|
||||
VALUE_PARAMETER name:b index:1 type:kotlin.Function0<kotlin.Unit>
|
||||
@@ -47,8 +43,7 @@ FILE fqName:<root> fileName:/samConversionsWithSmartCasts.kt
|
||||
then: BLOCK type=kotlin.Unit origin=null
|
||||
CALL 'public open fun run2 (r1: @[FlexibleNullability] java.lang.Runnable?, r2: @[FlexibleNullability] java.lang.Runnable?): kotlin.Unit declared in <root>.J' type=kotlin.Unit origin=null
|
||||
$this: CONSTRUCTOR_CALL 'public constructor <init> () declared in <root>.J' type=<root>.J origin=null
|
||||
r1: TYPE_OP type=kotlin.Any origin=IMPLICIT_CAST typeOperand=kotlin.Any
|
||||
GET_VAR 'a: kotlin.Function0<kotlin.Unit> declared in <root>.test4' type=kotlin.Function0<kotlin.Unit> origin=null
|
||||
r1: GET_VAR 'a: kotlin.Function0<kotlin.Unit> declared in <root>.test4' type=kotlin.Function0<kotlin.Unit> origin=null
|
||||
r2: TYPE_OP type=@[FlexibleNullability] java.lang.Runnable? origin=SAM_CONVERSION typeOperand=@[FlexibleNullability] java.lang.Runnable?
|
||||
GET_VAR 'b: kotlin.Function0<kotlin.Unit> declared in <root>.test4' type=kotlin.Function0<kotlin.Unit> origin=null
|
||||
FUN name:test5 visibility:public modality:FINAL <> (a:kotlin.Any) returnType:kotlin.Unit
|
||||
@@ -98,8 +93,7 @@ FILE fqName:<root> fileName:/samConversionsWithSmartCasts.kt
|
||||
CALL 'public open fun run1 (r: @[FlexibleNullability] java.lang.Runnable?): kotlin.Unit declared in <root>.J' type=kotlin.Unit origin=null
|
||||
$this: CONSTRUCTOR_CALL 'public constructor <init> () declared in <root>.J' type=<root>.J origin=null
|
||||
r: TYPE_OP type=@[FlexibleNullability] java.lang.Runnable? origin=SAM_CONVERSION typeOperand=@[FlexibleNullability] java.lang.Runnable?
|
||||
TYPE_OP type=kotlin.Function<kotlin.Any> origin=IMPLICIT_CAST typeOperand=kotlin.Function<kotlin.Any>
|
||||
GET_VAR 'a: kotlin.Function1<kotlin.Int, kotlin.Int> declared in <root>.test7' type=kotlin.Function1<kotlin.Int, kotlin.Int> origin=null
|
||||
GET_VAR 'a: kotlin.Function1<kotlin.Int, kotlin.Int> declared in <root>.test7' type=kotlin.Function1<kotlin.Int, kotlin.Int> origin=null
|
||||
FUN name:test8 visibility:public modality:FINAL <> (a:kotlin.Function0<kotlin.Unit>) returnType:kotlin.Unit
|
||||
VALUE_PARAMETER name:a index:0 type:kotlin.Function0<kotlin.Unit>
|
||||
BLOCK_BODY
|
||||
|
||||
+5
-5
@@ -1,7 +1,7 @@
|
||||
fun test1(a: Function0<Unit>) {
|
||||
when {
|
||||
a is Runnable -> { // BLOCK
|
||||
runStatic(r = a /*as Any */)
|
||||
runStatic(r = a)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ fun test1(a: Function0<Unit>) {
|
||||
fun test2(a: Function0<Unit>) {
|
||||
when {
|
||||
a is Runnable -> { // BLOCK
|
||||
J().run1(r = a /*as Any */)
|
||||
J().run1(r = a)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@ fun test2(a: Function0<Unit>) {
|
||||
fun test3(a: Function0<Unit>) {
|
||||
when {
|
||||
a is Runnable -> { // BLOCK
|
||||
J().run2(r1 = a /*as Any */, r2 = a /*as Any */)
|
||||
J().run2(r1 = a, r2 = a)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,7 @@ fun test3(a: Function0<Unit>) {
|
||||
fun test4(a: Function0<Unit>, b: Function0<Unit>) {
|
||||
when {
|
||||
a is Runnable -> { // BLOCK
|
||||
J().run2(r1 = a /*as Any */, r2 = b /*-> @FlexibleNullability Runnable? */)
|
||||
J().run2(r1 = a, r2 = b /*-> @FlexibleNullability Runnable? */)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -54,7 +54,7 @@ fun test6(a: Any) {
|
||||
|
||||
fun test7(a: Function1<Int, Int>) {
|
||||
a as Function0<Unit> /*~> Unit */
|
||||
J().run1(r = a /*as Function<Any> */ /*-> @FlexibleNullability Runnable? */)
|
||||
J().run1(r = a /*-> @FlexibleNullability Runnable? */)
|
||||
}
|
||||
|
||||
fun test8(a: Function0<Unit>) {
|
||||
|
||||
+1
-2
@@ -49,8 +49,7 @@ FILE fqName:<root> fileName:/smartCastsWithDestructuring.kt
|
||||
then: RETURN type=kotlin.Nothing from='public final fun test (x: <root>.I1): kotlin.Unit declared in <root>'
|
||||
GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Unit modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.Unit
|
||||
VAR IR_TEMPORARY_VARIABLE name:tmp_0 type:<root>.I1 [val]
|
||||
TYPE_OP type=kotlin.Any origin=IMPLICIT_CAST typeOperand=kotlin.Any
|
||||
GET_VAR 'x: <root>.I1 declared in <root>.test' type=<root>.I1 origin=null
|
||||
GET_VAR 'x: <root>.I1 declared in <root>.test' type=<root>.I1 origin=null
|
||||
VAR name:c1 type:kotlin.Int [val]
|
||||
CALL 'public final fun component1 (): kotlin.Int declared in <root>' type=kotlin.Int origin=COMPONENT_N(index=1)
|
||||
$receiver: GET_VAR 'val tmp_0: <root>.I1 declared in <root>.test' type=<root>.I1 origin=null
|
||||
|
||||
+2
-1
@@ -18,7 +18,8 @@ fun test(x: I1) {
|
||||
when {
|
||||
x !is I2 -> return Unit
|
||||
}
|
||||
val tmp_0: I1 = x /*as Any */
|
||||
val tmp_0: I1 = x
|
||||
val c1: Int = tmp_0.component1()
|
||||
val c2: String = tmp_0 /*as I2 */.component2()
|
||||
}
|
||||
|
||||
|
||||
+2
-4
@@ -254,8 +254,7 @@ FILE fqName:<root> fileName:/suspendConversionOnArbitraryExpression.kt
|
||||
TYPE_OP type=kotlin.coroutines.SuspendFunction0<kotlin.Unit> origin=CAST typeOperand=kotlin.coroutines.SuspendFunction0<kotlin.Unit>
|
||||
GET_VAR 'a: kotlin.Function0<kotlin.Unit> declared in <root>.testSmartCastVsSuspendConversion' type=kotlin.Function0<kotlin.Unit> origin=null
|
||||
CALL 'public final fun useSuspend (sfn: kotlin.coroutines.SuspendFunction0<kotlin.Unit>): kotlin.Unit declared in <root>' type=kotlin.Unit origin=null
|
||||
sfn: TYPE_OP type=kotlin.Function<kotlin.Unit> origin=IMPLICIT_CAST typeOperand=kotlin.Function<kotlin.Unit>
|
||||
GET_VAR 'a: kotlin.Function0<kotlin.Unit> declared in <root>.testSmartCastVsSuspendConversion' type=kotlin.Function0<kotlin.Unit> origin=null
|
||||
sfn: GET_VAR 'a: kotlin.Function0<kotlin.Unit> declared in <root>.testSmartCastVsSuspendConversion' type=kotlin.Function0<kotlin.Unit> origin=null
|
||||
FUN name:testSmartCastOnVarVsSuspendConversion visibility:public modality:FINAL <> (a:kotlin.Function0<kotlin.Unit>) returnType:kotlin.Unit
|
||||
VALUE_PARAMETER name:a index:0 type:kotlin.Function0<kotlin.Unit>
|
||||
BLOCK_BODY
|
||||
@@ -265,8 +264,7 @@ FILE fqName:<root> fileName:/suspendConversionOnArbitraryExpression.kt
|
||||
TYPE_OP type=kotlin.coroutines.SuspendFunction0<kotlin.Unit> origin=CAST typeOperand=kotlin.coroutines.SuspendFunction0<kotlin.Unit>
|
||||
GET_VAR 'var b: kotlin.Function0<kotlin.Unit> declared in <root>.testSmartCastOnVarVsSuspendConversion' type=kotlin.Function0<kotlin.Unit> origin=null
|
||||
CALL 'public final fun useSuspend (sfn: kotlin.coroutines.SuspendFunction0<kotlin.Unit>): kotlin.Unit declared in <root>' type=kotlin.Unit origin=null
|
||||
sfn: TYPE_OP type=kotlin.Function<kotlin.Unit> origin=IMPLICIT_CAST typeOperand=kotlin.Function<kotlin.Unit>
|
||||
GET_VAR 'var b: kotlin.Function0<kotlin.Unit> declared in <root>.testSmartCastOnVarVsSuspendConversion' type=kotlin.Function0<kotlin.Unit> origin=null
|
||||
sfn: GET_VAR 'var b: kotlin.Function0<kotlin.Unit> declared in <root>.testSmartCastOnVarVsSuspendConversion' type=kotlin.Function0<kotlin.Unit> origin=null
|
||||
FUN name:testIntersectionVsSuspendConversion visibility:public modality:FINAL <T> (x:T of <root>.testIntersectionVsSuspendConversion) returnType:kotlin.Unit
|
||||
TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Function0<kotlin.Unit>; kotlin.coroutines.SuspendFunction0<kotlin.Unit>] reified:false
|
||||
VALUE_PARAMETER name:x index:0 type:T of <root>.testIntersectionVsSuspendConversion
|
||||
|
||||
+2
-2
@@ -175,13 +175,13 @@ fun testSmartCastOnVarWithSuspendConversion(a: Any) {
|
||||
|
||||
fun testSmartCastVsSuspendConversion(a: Function0<Unit>) {
|
||||
a as SuspendFunction0<Unit> /*~> Unit */
|
||||
useSuspend(sfn = a /*as Function<Unit> */)
|
||||
useSuspend(sfn = a)
|
||||
}
|
||||
|
||||
fun testSmartCastOnVarVsSuspendConversion(a: Function0<Unit>) {
|
||||
var b: Function0<Unit> = a
|
||||
b as SuspendFunction0<Unit> /*~> Unit */
|
||||
useSuspend(sfn = b /*as Function<Unit> */)
|
||||
useSuspend(sfn = b)
|
||||
}
|
||||
|
||||
fun <T> testIntersectionVsSuspendConversion(x: T) where T : Function0<Unit>, T : SuspendFunction0<Unit> {
|
||||
|
||||
Reference in New Issue
Block a user