diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java index 1ec3123f3d9..79afd49d484 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java @@ -3046,7 +3046,9 @@ public class ExpressionCodegen extends KtVisitor impleme } } else if (receiverDescriptor instanceof ScriptDescriptor) { - return generateScriptReceiver((ScriptDescriptor) receiverDescriptor); + StackValue contextReceiverValueOrNull = generateScriptReceiver((ScriptDescriptor) receiverDescriptor); + + return contextReceiverValueOrNull != null ? contextReceiverValueOrNull : StackValue.thisOrOuter(this, receiverDescriptor, isSuper, castReceiver); } else { return StackValue.thisOrOuter(this, receiverDescriptor, isSuper, castReceiver); @@ -3126,7 +3128,6 @@ public class ExpressionCodegen extends KtVisitor impleme return result; } - @NotNull private StackValue generateScriptReceiver(@NotNull ScriptDescriptor receiver) { CodegenContext cur = context; StackValue result = StackValue.LOCAL_0; @@ -3149,8 +3150,8 @@ public class ExpressionCodegen extends KtVisitor impleme String fieldName = scriptContext.getScriptFieldName(receiver); return StackValue.field(classType, receiverKotlinType, currentScriptType, fieldName, false, result, receiver); } - - result = cur.getOuterExpression(result, false); + // might be null inside the generated synthetic class during expression evaluation + result = cur.getOuterExpression(result, true); if (inStartConstructorContext) { cur = getNotNullParentContextForMethod(cur); @@ -3160,7 +3161,7 @@ public class ExpressionCodegen extends KtVisitor impleme cur = cur.getParentContext(); } - throw new UnsupportedOperationException(); + return result; } @NotNull