Skip to content

Commit

Permalink
Scripting, IR: fix capturing of implicit receiver
Browse files Browse the repository at this point in the history
#KT-55068 fixed
  • Loading branch information
ligee authored and qodana-bot committed Dec 12, 2022
1 parent 06cbf8f commit f603c0e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -442,18 +442,22 @@ private class ScriptToClassTransformer(
transformAnnotations(data)
typeRemapper.withinScope(this) {
val newDispatchReceiverParameter = dispatchReceiverParameter?.transform(data)
val isInScriptConstructor = this@transformFunctionChildren is IrConstructor && parent == irScript
val dataForChildren =
when {
newDispatchReceiverParameter == null -> data

newDispatchReceiverParameter.type == scriptClassReceiver.type ->
ScriptToClassTransformerContext(newDispatchReceiverParameter.symbol, null, null, this is IrConstructor)
ScriptToClassTransformerContext(newDispatchReceiverParameter.symbol, null, null, isInScriptConstructor)

newDispatchReceiverParameter.type == data.valueParameterForFieldReceiver?.owner?.type ->
ScriptToClassTransformerContext(
null,
data.fieldForScriptThis,
newDispatchReceiverParameter.symbol,
this is IrConstructor
isInScriptConstructor
)

else -> data
}
dispatchReceiverParameter = newDispatchReceiverParameter
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// IGNORE_BACKEND: JS, JS_IR, JS_IR_ES6, NATIVE, WASM, JVM_OLD
// KOTLIN_SCRIPT_DEFINITION: org.jetbrains.kotlin.codegen.TestScriptWithReceivers

// receiver: abracadabra
// expected: rv=cadabra

// KT-55068

class User(var property: String = drop(4))

val rv = User().property

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f603c0e

Please sign in to comment.