From 28e232f54fc1f3e7b82cb771b909f0998bcf5fa7 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Mon, 14 Aug 2023 22:47:37 +0200 Subject: [PATCH] Kapt tests: minor, add case with optimized delegated property In normal circumstances, it leads to the field `c$delegate` NOT being generated (see KT-39054). However, it's not the case in kapt in any mode: - In the old JVM backend, this optimization is not supported. - In JVM IR, property initializers are missing in light analysis, so backend cannot figure out that this property is optimizable. - In kapt4, backend is not being run, and symbol light classes do not have information about this optimization. Overall it doesn't matter much which stub is generated here because the field is private, the test is added just in case. --- .../testData/converter/delegatedProperties.fir.txt | 12 ++++++++++++ .../testData/converter/delegatedProperties.ir.txt | 12 ++++++++++++ .../testData/converter/delegatedProperties.kt | 1 + .../testData/converter/delegatedProperties.txt | 12 ++++++++++++ 4 files changed, 37 insertions(+) diff --git a/plugins/kapt3/kapt3-compiler/testData/converter/delegatedProperties.fir.txt b/plugins/kapt3/kapt3-compiler/testData/converter/delegatedProperties.fir.txt index cb6fe0e709f..d9ecbf9d2bf 100644 --- a/plugins/kapt3/kapt3-compiler/testData/converter/delegatedProperties.fir.txt +++ b/plugins/kapt3/kapt3-compiler/testData/converter/delegatedProperties.fir.txt @@ -16,6 +16,11 @@ package test; * public final (* delegated *) val b: test/C * public final (* non-default *) get * + * // field: c$delegate:Lkotlin/reflect/KProperty0; + * // getter: getC()Ltest/C; + * public final (* delegated *) val c: test/C + * public final (* non-default *) get + * * // field: x$delegate:Lkotlin/Lazy; * // getter: getX()Lerror/NonExistentClass; * // synthetic method for annotations: getX$annotations()V @@ -47,6 +52,8 @@ public final class A { private final kotlin.Lazy> a$delegate = null; @org.jetbrains.annotations.NotNull() private final kotlin.Lazy> b$delegate = null; + @org.jetbrains.annotations.NotNull() + private final kotlin.reflect.KProperty0> c$delegate = null; public A() { super(); @@ -80,6 +87,11 @@ public final class A { public final test.C getB() { return null; } + + @org.jetbrains.annotations.NotNull() + public final test.C getC() { + return null; + } } //////////////////// diff --git a/plugins/kapt3/kapt3-compiler/testData/converter/delegatedProperties.ir.txt b/plugins/kapt3/kapt3-compiler/testData/converter/delegatedProperties.ir.txt index 2a4a3165b58..840ba4ca26b 100644 --- a/plugins/kapt3/kapt3-compiler/testData/converter/delegatedProperties.ir.txt +++ b/plugins/kapt3/kapt3-compiler/testData/converter/delegatedProperties.ir.txt @@ -16,6 +16,11 @@ package test; * public final (* delegated *) val b: test/C * public final (* non-default *) get * + * // field: c$delegate:Lkotlin/reflect/KProperty0; + * // getter: getC()Ltest/C; + * public final (* delegated *) val c: test/C + * public final (* non-default *) get + * * // field: x$delegate:Lkotlin/Lazy; * // getter: getX()Lkotlin/Unit; * // synthetic method for annotations: getX$annotations()V @@ -47,6 +52,8 @@ public final class A { private final kotlin.Lazy a$delegate = null; @org.jetbrains.annotations.NotNull() private final kotlin.Lazy b$delegate = null; + @org.jetbrains.annotations.NotNull() + private final kotlin.reflect.KProperty0 c$delegate = null; public A() { super(); @@ -81,6 +88,11 @@ public final class A { public final test.C getB() { return null; } + + @org.jetbrains.annotations.NotNull() + public final test.C getC() { + return null; + } } //////////////////// diff --git a/plugins/kapt3/kapt3-compiler/testData/converter/delegatedProperties.kt b/plugins/kapt3/kapt3-compiler/testData/converter/delegatedProperties.kt index 09ed876fdd8..49236d50fa6 100644 --- a/plugins/kapt3/kapt3-compiler/testData/converter/delegatedProperties.kt +++ b/plugins/kapt3/kapt3-compiler/testData/converter/delegatedProperties.kt @@ -11,4 +11,5 @@ class A { val y by object: C("y") {} val a by lazy { C("a") } val b by lazy { object: C("b") {} } + val c by ::a } diff --git a/plugins/kapt3/kapt3-compiler/testData/converter/delegatedProperties.txt b/plugins/kapt3/kapt3-compiler/testData/converter/delegatedProperties.txt index cc8a6e7a87a..8039006ba8f 100644 --- a/plugins/kapt3/kapt3-compiler/testData/converter/delegatedProperties.txt +++ b/plugins/kapt3/kapt3-compiler/testData/converter/delegatedProperties.txt @@ -16,6 +16,11 @@ package test; * public final (* delegated *) val b: test/C * public final (* non-default *) get * + * // field: c$delegate:Lkotlin/reflect/KProperty0; + * // getter: getC()Ltest/C; + * public final (* delegated *) val c: test/C + * public final (* non-default *) get + * * // field: x$delegate:Lkotlin/Lazy; * // getter: getX()Lkotlin/Unit; * // synthetic method for annotations: getX$annotations()V @@ -47,6 +52,8 @@ public final class A { private final kotlin.Lazy a$delegate = null; @org.jetbrains.annotations.NotNull() private final kotlin.Lazy b$delegate = null; + @org.jetbrains.annotations.NotNull() + private final kotlin.reflect.KProperty0 c$delegate = null; public A() { super(); @@ -81,6 +88,11 @@ public final class A { public final test.C getB() { return null; } + + @org.jetbrains.annotations.NotNull() + public final test.C getC() { + return null; + } } ////////////////////