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:
+14
@@ -0,0 +1,14 @@
|
||||
MODULE_FRAGMENT
|
||||
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] kotlin.Function0<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
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
// WITH_FIR_TEST_COMPILER_PLUGIN
|
||||
// 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)
|
||||
// MODULE_KIND: Source
|
||||
// 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
|
||||
)
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
final class MainKt$Bar$1 {
|
||||
// source: 'main.kt'
|
||||
enclosing method MainKt.Bar()V
|
||||
public final static field INSTANCE: MainKt$Bar$1
|
||||
inner (anonymous) class MainKt$Bar$1
|
||||
static method <clinit>(): void
|
||||
method <init>(): void
|
||||
public synthetic bridge method invoke(): java.lang.Object
|
||||
public final method invoke(): void
|
||||
}
|
||||
|
||||
public final class MainKt {
|
||||
// source: 'main.kt'
|
||||
inner (anonymous) class MainKt$Bar$1
|
||||
public final static method Bar(): void
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
MODULE_FRAGMENT
|
||||
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: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] kotlin.Function0<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"
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
// WITH_FIR_TEST_COMPILER_PLUGIN
|
||||
// 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)
|
||||
// MODULE_KIND: Source
|
||||
// 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) {}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
final class MainKt$test$1 {
|
||||
// source: 'main.kt'
|
||||
enclosing method MainKt.test()I
|
||||
public final static field INSTANCE: MainKt$test$1
|
||||
inner (anonymous) class MainKt$test$1
|
||||
static method <clinit>(): void
|
||||
method <init>(): void
|
||||
public synthetic bridge method invoke(): java.lang.Object
|
||||
public final method invoke(): void
|
||||
}
|
||||
|
||||
public final class MainKt {
|
||||
// source: 'main.kt'
|
||||
inner (anonymous) class MainKt$test$1
|
||||
public final static method Greeting(p0: java.lang.String): void
|
||||
public final static method show(p0: java.lang.String): void
|
||||
public final static method test(): int
|
||||
}
|
||||
Reference in New Issue
Block a user