Psi2ir: fix parameter indices when generating extension invoke call

Incorrect `valueParameter` was passed to `generateValueArgument`, which
resulted in incorrect type being considered for generating suspend
conversion.

 #KT-50949 Fixed
This commit is contained in:
Alexander Udalov
2022-03-08 23:59:26 +01:00
parent c2ab23ed70
commit 1e26888dd9
16 changed files with 138 additions and 3 deletions
@@ -0,0 +1,28 @@
FILE fqName:<root> fileName:/suspendConversionForExtensionFunction.kt
FUN name:main visibility:public modality:FINAL <> () returnType:kotlin.Unit
BLOCK_BODY
VAR name:foo type:@[ExtensionFunctionType] kotlin.Function2<kotlin.String, kotlin.coroutines.SuspendFunction0<kotlin.Unit>, kotlin.Unit> [val]
FUN_EXPR type=@[ExtensionFunctionType] kotlin.Function2<kotlin.String, kotlin.coroutines.SuspendFunction0<kotlin.Unit>, kotlin.Unit> origin=LAMBDA
FUN LOCAL_FUNCTION_FOR_LAMBDA name:<anonymous> visibility:local modality:FINAL <> ($receiver:kotlin.String, it:kotlin.coroutines.SuspendFunction0<kotlin.Unit>) returnType:kotlin.Unit
$receiver: VALUE_PARAMETER name:<this> type:kotlin.String
VALUE_PARAMETER name:it index:0 type:kotlin.coroutines.SuspendFunction0<kotlin.Unit>
BLOCK_BODY
RETURN type=kotlin.Nothing from='local final fun <anonymous> (it: kotlin.coroutines.SuspendFunction0<kotlin.Unit>): kotlin.Unit declared in <root>.main'
GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Unit modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.Unit
VAR name:f type:kotlin.Function0<kotlin.Unit> [val]
FUN_EXPR type=kotlin.Function0<kotlin.Unit> origin=LAMBDA
FUN LOCAL_FUNCTION_FOR_LAMBDA name:<anonymous> visibility:local modality:FINAL <> () returnType:kotlin.Unit
BLOCK_BODY
RETURN type=kotlin.Nothing from='local final fun <anonymous> (): kotlin.Unit declared in <root>.main'
GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Unit modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.Unit
CALL 'public abstract fun invoke (p1: P1 of kotlin.Function2, p2: P2 of kotlin.Function2): R of kotlin.Function2 [operator] declared in kotlin.Function2' type=kotlin.Unit origin=INVOKE
$this: GET_VAR 'val foo: @[ExtensionFunctionType] kotlin.Function2<kotlin.String, kotlin.coroutines.SuspendFunction0<kotlin.Unit>, kotlin.Unit> [val] declared in <root>.main' type=@[ExtensionFunctionType] kotlin.Function2<kotlin.String, kotlin.coroutines.SuspendFunction0<kotlin.Unit>, kotlin.Unit> origin=VARIABLE_AS_FUNCTION
p1: CONST String type=kotlin.String value=""
p2: BLOCK type=kotlin.coroutines.SuspendFunction0<kotlin.Unit> origin=SUSPEND_CONVERSION
FUN ADAPTER_FOR_SUSPEND_CONVERSION name:suspendConversion visibility:local modality:FINAL <> ($receiver:kotlin.Function0<kotlin.Unit>) returnType:kotlin.Unit [suspend]
$receiver: VALUE_PARAMETER ADAPTER_PARAMETER_FOR_SUSPEND_CONVERSION name:callee type:kotlin.Function0<kotlin.Unit>
BLOCK_BODY
CALL 'public abstract fun invoke (): R of kotlin.Function0 [operator] declared in kotlin.Function0' type=kotlin.Unit origin=null
$this: GET_VAR 'callee: kotlin.Function0<kotlin.Unit> declared in <root>.main.suspendConversion' type=kotlin.Function0<kotlin.Unit> origin=null
FUNCTION_REFERENCE 'local final fun suspendConversion (): kotlin.Unit [suspend] declared in <root>.main' type=kotlin.coroutines.SuspendFunction0<kotlin.Unit> origin=SUSPEND_CONVERSION reflectionTarget=null
$receiver: GET_VAR 'val f: kotlin.Function0<kotlin.Unit> [val] declared in <root>.main' type=kotlin.Function0<kotlin.Unit> origin=null
@@ -0,0 +1,28 @@
FILE fqName:<root> fileName:/suspendConversionForExtensionFunction.kt
FUN name:main visibility:public modality:FINAL <> () returnType:kotlin.Unit
BLOCK_BODY
VAR name:foo type:@[ExtensionFunctionType] kotlin.Function2<kotlin.String, kotlin.coroutines.SuspendFunction0<kotlin.Unit>, kotlin.Unit> [val]
FUN_EXPR type=@[ExtensionFunctionType] kotlin.Function2<kotlin.String, kotlin.coroutines.SuspendFunction0<kotlin.Unit>, kotlin.Unit> origin=LAMBDA
FUN LOCAL_FUNCTION_FOR_LAMBDA name:<anonymous> visibility:local modality:FINAL <> ($receiver:kotlin.String, it:kotlin.coroutines.SuspendFunction0<kotlin.Unit>) returnType:kotlin.Unit
$receiver: VALUE_PARAMETER name:$this$null type:kotlin.String
VALUE_PARAMETER name:it index:0 type:kotlin.coroutines.SuspendFunction0<kotlin.Unit>
BLOCK_BODY
RETURN type=kotlin.Nothing from='local final fun <anonymous> (it: kotlin.coroutines.SuspendFunction0<kotlin.Unit>): kotlin.Unit declared in <root>.main'
GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Unit modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.Unit
VAR name:f type:kotlin.Function0<kotlin.Unit> [val]
FUN_EXPR type=kotlin.Function0<kotlin.Unit> origin=LAMBDA
FUN LOCAL_FUNCTION_FOR_LAMBDA name:<anonymous> visibility:local modality:FINAL <> () returnType:kotlin.Unit
BLOCK_BODY
RETURN type=kotlin.Nothing from='local final fun <anonymous> (): kotlin.Unit declared in <root>.main'
GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Unit modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.Unit
CALL 'public abstract fun invoke (p1: P1 of kotlin.Function2, p2: P2 of kotlin.Function2): R of kotlin.Function2 [operator] declared in kotlin.Function2' type=kotlin.Unit origin=INVOKE
$this: GET_VAR 'val foo: @[ExtensionFunctionType] kotlin.Function2<kotlin.String, kotlin.coroutines.SuspendFunction0<kotlin.Unit>, kotlin.Unit> [val] declared in <root>.main' type=@[ExtensionFunctionType] kotlin.Function2<kotlin.String, kotlin.coroutines.SuspendFunction0<kotlin.Unit>, kotlin.Unit> origin=VARIABLE_AS_FUNCTION
p1: CONST String type=kotlin.String value=""
p2: BLOCK type=kotlin.coroutines.SuspendFunction0<kotlin.Unit> origin=SUSPEND_CONVERSION
FUN ADAPTER_FOR_SUSPEND_CONVERSION name:suspendConversion0 visibility:local modality:FINAL <> ($receiver:kotlin.Function0<kotlin.Unit>) returnType:kotlin.Unit [suspend]
$receiver: VALUE_PARAMETER ADAPTER_PARAMETER_FOR_SUSPEND_CONVERSION name:callee type:kotlin.Function0<kotlin.Unit>
BLOCK_BODY
CALL 'public abstract fun invoke (): R of kotlin.Function0 [operator] declared in kotlin.Function0' type=kotlin.Unit origin=null
$this: GET_VAR 'callee: kotlin.Function0<kotlin.Unit> declared in <root>.main.suspendConversion0' type=kotlin.Function0<kotlin.Unit> origin=null
FUNCTION_REFERENCE 'local final fun suspendConversion0 (): kotlin.Unit [suspend] declared in <root>.main' type=kotlin.coroutines.SuspendFunction0<kotlin.Unit> origin=SUSPEND_CONVERSION reflectionTarget=null
$receiver: GET_VAR 'val f: kotlin.Function0<kotlin.Unit> [val] declared in <root>.main' type=kotlin.Function0<kotlin.Unit> origin=null
@@ -0,0 +1,8 @@
// SKIP_KT_DUMP
// !LANGUAGE: +SuspendConversion
fun main() {
val foo: String.(suspend () -> Unit) -> Unit = {}
val f: () -> Unit = {}
"".foo(f)
}