K2: Use deserialized type annotation for lambda type resolution.
This commit adds code to check whether a deserialized cone type is a special function type kind or not when resolving the type of a lambda expression (anonymous function). If it is a special function kind, it sets the type of lambda based on the special function kind. ^KT-64994 Fixed
This commit is contained in:
+25
@@ -0,0 +1,25 @@
|
||||
Module: lib
|
||||
FILE fqName:p3 fileName:/foo.kt
|
||||
FUN name:Foo visibility:public modality:FINAL <> (text:@[MyComposable] kotlin.Function0<kotlin.Unit>) returnType:kotlin.Unit
|
||||
annotations:
|
||||
MyComposable
|
||||
VALUE_PARAMETER name:text index:0 type:@[MyComposable] kotlin.Function0<kotlin.Unit>
|
||||
BLOCK_BODY
|
||||
Module: main
|
||||
FILE fqName:<root> fileName:/main.kt
|
||||
FUN name:Bar visibility:public modality:FINAL <> () returnType:kotlin.Unit
|
||||
annotations:
|
||||
MyComposable
|
||||
BLOCK_BODY
|
||||
CALL 'public final fun Foo (text: @[MyComposable] some.MyComposableFunction0<kotlin.Unit>): kotlin.Unit declared in p3' type=kotlin.Unit origin=null
|
||||
text: FUN_EXPR type=kotlin.Function0<kotlin.Unit> origin=LAMBDA
|
||||
FUN LOCAL_FUNCTION_FOR_LAMBDA name:<anonymous> visibility:local modality:FINAL <> () returnType:kotlin.Unit
|
||||
annotations:
|
||||
MyComposable
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='local final fun <anonymous> (): kotlin.Unit declared in <root>.Bar'
|
||||
GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Unit modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.Unit
|
||||
FUN name:box visibility:public modality:FINAL <> () returnType:kotlin.String
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun box (): kotlin.String declared in <root>'
|
||||
CONST String type=kotlin.String value="OK"
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
Module: lib
|
||||
FILE: foo.kt
|
||||
package p3
|
||||
|
||||
@R|org/jetbrains/kotlin/fir/plugin/MyComposable|() public final fun Foo(text: R|@R|org/jetbrains/kotlin/fir/plugin/MyComposable|() some/MyComposableFunction0<kotlin/Unit>|): R|kotlin/Unit| {
|
||||
}
|
||||
Module: main
|
||||
FILE: main.kt
|
||||
@R|org/jetbrains/kotlin/fir/plugin/MyComposable|() public final fun Bar(): R|kotlin/Unit| {
|
||||
R|p3/Foo|(text = Foo@fun <anonymous>(): R|kotlin/Unit| <inline=NoInline> {
|
||||
^@Foo Unit
|
||||
}
|
||||
)
|
||||
}
|
||||
public final fun box(): R|kotlin/String| {
|
||||
^box String(OK)
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
// DUMP_IR
|
||||
|
||||
// MODULE: lib
|
||||
// FILE: p3/foo.kt
|
||||
|
||||
package p3;
|
||||
|
||||
import org.jetbrains.kotlin.fir.plugin.MyComposable
|
||||
|
||||
@MyComposable
|
||||
public fun Foo(
|
||||
text: @MyComposable () -> Unit,
|
||||
) {}
|
||||
|
||||
// MODULE: main(lib)
|
||||
// FILE: main.kt
|
||||
|
||||
import org.jetbrains.kotlin.fir.plugin.MyComposable
|
||||
import p3.Foo
|
||||
|
||||
@MyComposable
|
||||
public fun Bar() {
|
||||
Foo(
|
||||
text = {}, // @Composable invocations can only happen from the context of a @Composable function
|
||||
)
|
||||
}
|
||||
|
||||
fun box(): String = "OK"
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
Module: lib
|
||||
FILE fqName:p3 fileName:/foo.kt
|
||||
FUN name:setContent visibility:public modality:FINAL <> (content:@[MyComposable] kotlin.Function0<kotlin.Unit>) returnType:kotlin.Int
|
||||
VALUE_PARAMETER name:content index:0 type:@[MyComposable] kotlin.Function0<kotlin.Unit>
|
||||
BLOCK_BODY
|
||||
CALL 'public abstract fun invoke (): R of kotlin.Function0 declared in kotlin.Function0' type=kotlin.Unit origin=null
|
||||
$this: GET_VAR 'content: @[MyComposable] kotlin.Function0<kotlin.Unit> declared in p3.setContent' type=@[MyComposable] kotlin.Function0<kotlin.Unit> origin=VARIABLE_AS_FUNCTION
|
||||
RETURN type=kotlin.Nothing from='public final fun setContent (content: @[MyComposable] kotlin.Function0<kotlin.Unit>): kotlin.Int declared in p3'
|
||||
CONST Int type=kotlin.Int value=3
|
||||
Module: main
|
||||
FILE fqName:<root> fileName:/main.kt
|
||||
FUN name:Greeting visibility:public modality:FINAL <> (name:kotlin.String) returnType:kotlin.Unit
|
||||
annotations:
|
||||
MyComposable
|
||||
VALUE_PARAMETER name:name index:0 type:kotlin.String
|
||||
BLOCK_BODY
|
||||
CALL 'public final fun show (str: kotlin.String): kotlin.Unit declared in <root>' type=kotlin.Unit origin=null
|
||||
str: STRING_CONCATENATION type=kotlin.String
|
||||
CONST String type=kotlin.String value="hi "
|
||||
GET_VAR 'name: kotlin.String declared in <root>.Greeting' type=kotlin.String origin=null
|
||||
CONST String type=kotlin.String value="!"
|
||||
FUN name:box visibility:public modality:FINAL <> () returnType:kotlin.String
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun box (): kotlin.String declared in <root>'
|
||||
CONST String type=kotlin.String value="OK"
|
||||
FUN name:show visibility:public modality:FINAL <> (str:kotlin.String) returnType:kotlin.Unit
|
||||
VALUE_PARAMETER name:str index:0 type:kotlin.String
|
||||
BLOCK_BODY
|
||||
FUN name:test visibility:public modality:FINAL <> () returnType:kotlin.Int
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun test (): kotlin.Int declared in <root>'
|
||||
CALL 'public final fun setContent (content: @[MyComposable] some.MyComposableFunction0<kotlin.Unit>): kotlin.Int declared in p3' type=kotlin.Int origin=null
|
||||
content: FUN_EXPR type=kotlin.Function0<kotlin.Unit> origin=LAMBDA
|
||||
FUN LOCAL_FUNCTION_FOR_LAMBDA name:<anonymous> visibility:local modality:FINAL <> () returnType:kotlin.Unit
|
||||
annotations:
|
||||
MyComposable
|
||||
BLOCK_BODY
|
||||
CALL 'public final fun Greeting (name: kotlin.String): kotlin.Unit declared in <root>' type=kotlin.Unit origin=null
|
||||
name: CONST String type=kotlin.String value="test"
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
Module: lib
|
||||
FILE: foo.kt
|
||||
package p3
|
||||
|
||||
public final fun setContent(content: R|@R|org/jetbrains/kotlin/fir/plugin/MyComposable|() some/MyComposableFunction0<kotlin/Unit>|): R|kotlin/Int| {
|
||||
R|<local>/content|.R|SubstitutionOverride<some/MyComposableFunction0.invoke: R|kotlin/Unit|>|()
|
||||
^setContent Int(3)
|
||||
}
|
||||
Module: main
|
||||
FILE: main.kt
|
||||
public final fun test(): R|kotlin/Int| {
|
||||
^test R|p3/setContent|(<L> = setContent@fun <anonymous>(): R|kotlin/Unit| <inline=NoInline> {
|
||||
R|/Greeting|(String(test))
|
||||
}
|
||||
)
|
||||
}
|
||||
@R|org/jetbrains/kotlin/fir/plugin/MyComposable|() public final fun Greeting(name: R|kotlin/String|): R|kotlin/Unit| {
|
||||
R|/show|(<strcat>(String(hi ), R|<local>/name|, String(!)))
|
||||
}
|
||||
public final fun show(str: R|kotlin/String|): R|kotlin/Unit| {
|
||||
}
|
||||
public final fun box(): R|kotlin/String| {
|
||||
^box String(OK)
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
// DUMP_IR
|
||||
|
||||
// MODULE: lib
|
||||
// FILE: p3/foo.kt
|
||||
|
||||
package p3;
|
||||
|
||||
import org.jetbrains.kotlin.fir.plugin.MyComposable
|
||||
|
||||
fun setContent(content: @MyComposable () -> Unit): Int {
|
||||
content()
|
||||
return 3
|
||||
}
|
||||
|
||||
// MODULE: main(lib)
|
||||
// FILE: main.kt
|
||||
|
||||
import org.jetbrains.kotlin.fir.plugin.MyComposable
|
||||
import p3.setContent
|
||||
|
||||
fun test(): Int {
|
||||
return setContent {
|
||||
Greeting("test")
|
||||
}
|
||||
}
|
||||
|
||||
@MyComposable
|
||||
fun Greeting(name: String) {
|
||||
show("hi $name!")
|
||||
}
|
||||
|
||||
fun show(str: String) {}
|
||||
|
||||
fun box(): String = "OK"
|
||||
+12
@@ -61,6 +61,18 @@ public class FirLightTreePluginBlackBoxCodegenTestGenerated extends AbstractFirL
|
||||
runTest("plugins/fir-plugin-prototype/testData/box/composableFunction.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("composableFunctionMultiModules.kt")
|
||||
public void testComposableFunctionMultiModules() {
|
||||
runTest("plugins/fir-plugin-prototype/testData/box/composableFunctionMultiModules.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("composableFunctionMultiModules2.kt")
|
||||
public void testComposableFunctionMultiModules2() {
|
||||
runTest("plugins/fir-plugin-prototype/testData/box/composableFunctionMultiModules2.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("expectComposableFunction.kt")
|
||||
public void testExpectComposableFunction() {
|
||||
|
||||
Reference in New Issue
Block a user