Proper script receiverValue for synthetic evaluation expression class;

tests in IJ commit: "[scripting] Introduce tests for KT-51755"
This commit is contained in:
Nikolay Egorov
2022-05-23 12:36:08 +03:00
committed by teamcity
parent ac395b21ea
commit 1c04162690
@@ -3046,7 +3046,9 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> 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<StackValue, StackValue> 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<StackValue, StackValue> 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<StackValue, StackValue> impleme
cur = cur.getParentContext();
}
throw new UnsupportedOperationException();
return result;
}
@NotNull