-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JVM IR: script is a valid container for local delegated properties
When serializing metadata for local delegated properties, we need to find a valid container class where to put it, and where kotlin-reflect will be able to find that metadata at runtime. Taking just the closest class lexically doesn't work, because in the attached test, it is a class for a lambda which does not have metadata and thus does not have a way to store any extra information. So, in 1663619 we started to look for the closest "non-synthetic" class to store this metadata. But apparently it was missed that script is a valid container class. In the test, this meant that no non-synthetic container classes were found to store the metadata, so we falled back to using the closest class anyway (see `?: this` in `rememberLocalProperty`), which turned out to be the lambda. After this change, metadata for local delegated property in a lambda will be stored in the script class, just like it's stored in the file class in the non-script case. #KT-55065 Fixed (cherry picked from commit 3ab2b82)
- Loading branch information
1 parent
c32cd10
commit ea33e72
Showing
5 changed files
with
37 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
compiler/testData/codegen/script/localDelegatedPropertyInLambda.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// WITH_REFLECT | ||
|
||
import kotlin.reflect.KProperty | ||
|
||
class Delegate { | ||
operator fun getValue(t: Any?, p: KProperty<*>): String = | ||
if (p.returnType.toString() == "kotlin.String") "OK" else "Fail: ${p.returnType}" | ||
} | ||
|
||
fun f(lambda: () -> String): String = lambda() | ||
|
||
val x = f { | ||
val prop: String by Delegate() | ||
prop | ||
} | ||
|
||
// expected: x: OK |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
compiler/tests-gen/org/jetbrains/kotlin/codegen/ScriptCodegenTestGenerated.java
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
5 changes: 5 additions & 0 deletions
5
compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/IrScriptCodegenTestGenerated.java
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.