when calling function stored in local variable as unary operation, don't forget to push function instance (KT-1953)
I'm sure that there are similar cases that still don't work; please let me know if you find any #KT-1953 fixed
This commit is contained in:
@@ -1023,19 +1023,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
||||
|
||||
int index = lookupLocal(descriptor);
|
||||
if (index >= 0) {
|
||||
if(descriptor instanceof VariableDescriptor) {
|
||||
Type sharedVarType = typeMapper.getSharedVarType(descriptor);
|
||||
final JetType outType = ((VariableDescriptor) descriptor).getType();
|
||||
if(sharedVarType != null) {
|
||||
return StackValue.shared(index, asmType(outType));
|
||||
}
|
||||
else {
|
||||
return StackValue.local(index, asmType(outType));
|
||||
}
|
||||
}
|
||||
else {
|
||||
return StackValue.local(index, TYPE_OBJECT);
|
||||
}
|
||||
return stackValueForLocal(descriptor, index);
|
||||
}
|
||||
|
||||
if (descriptor instanceof PropertyDescriptor) {
|
||||
@@ -1157,6 +1145,22 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
||||
return value;
|
||||
}
|
||||
|
||||
private StackValue stackValueForLocal(DeclarationDescriptor descriptor, int index) {
|
||||
if(descriptor instanceof VariableDescriptor) {
|
||||
Type sharedVarType = typeMapper.getSharedVarType(descriptor);
|
||||
final JetType outType = ((VariableDescriptor) descriptor).getType();
|
||||
if(sharedVarType != null) {
|
||||
return StackValue.shared(index, asmType(outType));
|
||||
}
|
||||
else {
|
||||
return StackValue.local(index, asmType(outType));
|
||||
}
|
||||
}
|
||||
else {
|
||||
return StackValue.local(index, TYPE_OBJECT);
|
||||
}
|
||||
}
|
||||
|
||||
public int lookupLocal(DeclarationDescriptor descriptor) {
|
||||
return myFrameMap.getIndex(descriptor);
|
||||
}
|
||||
@@ -2198,6 +2202,10 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
||||
}
|
||||
|
||||
private StackValue invokeOperation(JetOperationExpression expression, FunctionDescriptor op, CallableMethod callable) {
|
||||
int functionLocalIndex = myFrameMap.getIndex(op);
|
||||
if (functionLocalIndex >= 0) {
|
||||
stackValueForLocal(op, functionLocalIndex).put(ClosureCodegen.getInternalClassName(op).getAsmType(), v);
|
||||
}
|
||||
ResolvedCall<? extends CallableDescriptor> resolvedCall = bindingContext.get(BindingContext.RESOLVED_CALL, expression.getOperationReference());
|
||||
assert resolvedCall != null;
|
||||
genThisAndReceiverFromResolvedCall(StackValue.none(), resolvedCall, callable);
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
fun box(): String {
|
||||
val sb = StringBuilder()
|
||||
fun String.plus() {
|
||||
sb.append(this)
|
||||
}
|
||||
|
||||
+"OK"
|
||||
return sb.toString()!!
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
class A {
|
||||
private val sb: StringBuilder = StringBuilder()
|
||||
|
||||
fun String.plus {
|
||||
sb.append(this)
|
||||
}
|
||||
|
||||
fun foo(): String {
|
||||
+"OK"
|
||||
return sb.toString()!!
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String = A().foo()
|
||||
@@ -96,4 +96,14 @@ public class ExtensionFunctionsTest extends CodegenTestCase {
|
||||
createEnvironmentWithMockJdkAndIdeaAnnotations(CompilerSpecialMode.BUILTINS);
|
||||
blackBoxFile("regressions/kt1290.kt");
|
||||
}
|
||||
|
||||
public void testKt1953() throws Exception {
|
||||
createEnvironmentWithMockJdkAndIdeaAnnotations(CompilerSpecialMode.JDK_HEADERS);
|
||||
blackBoxFile("regressions/kt1953.kt");
|
||||
}
|
||||
|
||||
public void testKt1953Class() throws Exception {
|
||||
createEnvironmentWithMockJdkAndIdeaAnnotations(CompilerSpecialMode.JDK_HEADERS);
|
||||
blackBoxFile("regressions/kt1953_class.kt");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user