[FIR2IR] Properly insert casts for smartcasts in argument position
Previously cast inserter didn't consider expected type for arguments of function calls ^KT-63257 Fixed
This commit is contained in:
committed by
Space Team
parent
c70a6425f5
commit
8578a0bf6a
Vendored
+10
-5
@@ -44,7 +44,8 @@ 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: GET_VAR 'a: kotlin.Function0<kotlin.Unit> declared in <root>.test1' type=kotlin.Function0<kotlin.Unit> origin=null
|
||||
r: TYPE_OP type=<root>.KRunnable origin=IMPLICIT_CAST typeOperand=<root>.KRunnable
|
||||
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
|
||||
@@ -62,8 +63,10 @@ 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: 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
|
||||
r1: TYPE_OP type=<root>.KRunnable origin=IMPLICIT_CAST typeOperand=<root>.KRunnable
|
||||
GET_VAR 'a: kotlin.Function0<kotlin.Unit> declared in <root>.test3' type=kotlin.Function0<kotlin.Unit> origin=null
|
||||
r2: TYPE_OP type=<root>.KRunnable origin=IMPLICIT_CAST typeOperand=<root>.KRunnable
|
||||
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>
|
||||
@@ -74,7 +77,8 @@ 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: GET_VAR 'a: kotlin.Function0<kotlin.Unit> declared in <root>.test4' type=kotlin.Function0<kotlin.Unit> origin=null
|
||||
r1: TYPE_OP type=<root>.KRunnable origin=IMPLICIT_CAST typeOperand=<root>.KRunnable
|
||||
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
|
||||
@@ -101,7 +105,8 @@ FILE fqName:<root> fileName:/samConversionsWithSmartCasts.kt
|
||||
TYPE_OP type=<root>.KRunnable origin=IMPLICIT_CAST typeOperand=<root>.KRunnable
|
||||
GET_VAR 'a: kotlin.Any declared in <root>.test5x' type=kotlin.Any origin=null
|
||||
CALL 'public final fun run1 (r: <root>.KRunnable): kotlin.Unit declared in <root>' type=kotlin.Unit origin=null
|
||||
r: GET_VAR 'a: kotlin.Any declared in <root>.test5x' type=kotlin.Any origin=null
|
||||
r: TYPE_OP type=<root>.KRunnable origin=IMPLICIT_CAST typeOperand=<root>.KRunnable
|
||||
GET_VAR 'a: kotlin.Any declared in <root>.test5x' type=kotlin.Any origin=null
|
||||
FUN name:test6 visibility:public modality:FINAL <> (a:kotlin.Any) returnType:kotlin.Unit
|
||||
VALUE_PARAMETER name:a index:0 type:kotlin.Any
|
||||
BLOCK_BODY
|
||||
|
||||
Vendored
+4
-4
@@ -20,7 +20,7 @@ fun <T> test0(a: T) where T : KRunnable, T : Function0<Unit> {
|
||||
fun test1(a: Function0<Unit>) {
|
||||
when {
|
||||
a is KRunnable -> { // BLOCK
|
||||
run1(r = a)
|
||||
run1(r = a /*as KRunnable */)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,7 +33,7 @@ fun test2(a: KRunnable) {
|
||||
fun test3(a: Function0<Unit>) {
|
||||
when {
|
||||
a is KRunnable -> { // BLOCK
|
||||
run2(r1 = a, r2 = a)
|
||||
run2(r1 = a /*as KRunnable */, r2 = a /*as KRunnable */)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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, r2 = b /*-> KRunnable */)
|
||||
run2(r1 = a /*as KRunnable */, r2 = b /*-> KRunnable */)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -58,7 +58,7 @@ fun test5x(a: Any) {
|
||||
when {
|
||||
a is KRunnable -> { // BLOCK
|
||||
a /*as KRunnable */ as Function0<Unit> /*~> Unit */
|
||||
run1(r = a)
|
||||
run1(r = a /*as KRunnable */)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+12
-6
@@ -8,7 +8,8 @@ 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: GET_VAR 'a: kotlin.Function0<kotlin.Unit> declared in <root>.test1' type=kotlin.Function0<kotlin.Unit> origin=null
|
||||
r: TYPE_OP type=java.lang.Runnable origin=IMPLICIT_CAST typeOperand=java.lang.Runnable
|
||||
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
|
||||
@@ -19,7 +20,8 @@ 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: GET_VAR 'a: kotlin.Function0<kotlin.Unit> declared in <root>.test2' type=kotlin.Function0<kotlin.Unit> origin=null
|
||||
r: TYPE_OP type=java.lang.Runnable origin=IMPLICIT_CAST typeOperand=java.lang.Runnable
|
||||
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
|
||||
@@ -30,8 +32,10 @@ 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: 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
|
||||
r1: TYPE_OP type=java.lang.Runnable origin=IMPLICIT_CAST typeOperand=java.lang.Runnable
|
||||
GET_VAR 'a: kotlin.Function0<kotlin.Unit> declared in <root>.test3' type=kotlin.Function0<kotlin.Unit> origin=null
|
||||
r2: TYPE_OP type=java.lang.Runnable origin=IMPLICIT_CAST typeOperand=java.lang.Runnable
|
||||
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>
|
||||
@@ -43,7 +47,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: GET_VAR 'a: kotlin.Function0<kotlin.Unit> declared in <root>.test4' type=kotlin.Function0<kotlin.Unit> origin=null
|
||||
r1: TYPE_OP type=java.lang.Runnable origin=IMPLICIT_CAST typeOperand=java.lang.Runnable
|
||||
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
|
||||
@@ -72,7 +77,8 @@ FILE fqName:<root> fileName:/samConversionsWithSmartCasts.kt
|
||||
GET_VAR 'a: kotlin.Any declared in <root>.test5x' type=kotlin.Any 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: GET_VAR 'a: kotlin.Any declared in <root>.test5x' type=kotlin.Any origin=null
|
||||
r: TYPE_OP type=java.lang.Runnable origin=IMPLICIT_CAST typeOperand=java.lang.Runnable
|
||||
GET_VAR 'a: kotlin.Any declared in <root>.test5x' type=kotlin.Any origin=null
|
||||
FUN name:test6 visibility:public modality:FINAL <> (a:kotlin.Any) returnType:kotlin.Unit
|
||||
VALUE_PARAMETER name:a index:0 type:kotlin.Any
|
||||
BLOCK_BODY
|
||||
|
||||
+5
-5
@@ -1,7 +1,7 @@
|
||||
fun test1(a: Function0<Unit>) {
|
||||
when {
|
||||
a is Runnable -> { // BLOCK
|
||||
runStatic(r = a)
|
||||
runStatic(r = a /*as Runnable */)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ fun test1(a: Function0<Unit>) {
|
||||
fun test2(a: Function0<Unit>) {
|
||||
when {
|
||||
a is Runnable -> { // BLOCK
|
||||
J().run1(r = a)
|
||||
J().run1(r = a /*as Runnable */)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@ fun test2(a: Function0<Unit>) {
|
||||
fun test3(a: Function0<Unit>) {
|
||||
when {
|
||||
a is Runnable -> { // BLOCK
|
||||
J().run2(r1 = a, r2 = a)
|
||||
J().run2(r1 = a /*as Runnable */, r2 = a /*as Runnable */)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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, r2 = b /*-> @FlexibleNullability Runnable? */)
|
||||
J().run2(r1 = a /*as Runnable */, r2 = b /*-> @FlexibleNullability Runnable? */)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -42,7 +42,7 @@ fun test5x(a: Any) {
|
||||
when {
|
||||
a is Runnable -> { // BLOCK
|
||||
a /*as Runnable */ as Function0<Unit> /*~> Unit */
|
||||
J().run1(r = a)
|
||||
J().run1(r = a /*as Runnable */)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-2
@@ -254,7 +254,8 @@ 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: GET_VAR 'a: kotlin.Function0<kotlin.Unit> declared in <root>.testSmartCastVsSuspendConversion' type=kotlin.Function0<kotlin.Unit> origin=null
|
||||
sfn: TYPE_OP type=kotlin.coroutines.SuspendFunction0<kotlin.Unit> origin=IMPLICIT_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
|
||||
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
|
||||
@@ -264,7 +265,8 @@ 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: GET_VAR 'var b: kotlin.Function0<kotlin.Unit> declared in <root>.testSmartCastOnVarVsSuspendConversion' type=kotlin.Function0<kotlin.Unit> origin=null
|
||||
sfn: TYPE_OP type=kotlin.coroutines.SuspendFunction0<kotlin.Unit> origin=IMPLICIT_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
|
||||
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)
|
||||
useSuspend(sfn = a /*as SuspendFunction0<Unit> */)
|
||||
}
|
||||
|
||||
fun testSmartCastOnVarVsSuspendConversion(a: Function0<Unit>) {
|
||||
var b: Function0<Unit> = a
|
||||
b as SuspendFunction0<Unit> /*~> Unit */
|
||||
useSuspend(sfn = b)
|
||||
useSuspend(sfn = b /*as SuspendFunction0<Unit> */)
|
||||
}
|
||||
|
||||
fun <T> testIntersectionVsSuspendConversion(x: T) where T : Function0<Unit>, T : SuspendFunction0<Unit> {
|
||||
|
||||
Reference in New Issue
Block a user