KT-33
This commit is contained in:
@@ -1970,23 +1970,25 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
final PsiElement declaration = BindingContextUtils.resolveToDeclarationPsiElement(bindingContext, expression);
|
DeclarationDescriptor operationDescriptor = bindingContext.get(BindingContext.REFERENCE_TARGET, expression);
|
||||||
assert declaration != null : "No declaration found for " + expression.getText();
|
CallableMethod accessor = typeMapper.mapToCallableMethod((FunctionDescriptor) operationDescriptor, OwnerKind.IMPLEMENTATION);
|
||||||
final CallableMethod accessor;
|
|
||||||
if (declaration instanceof PsiMethod) {
|
boolean isGetter = accessor.getSignature().getName().equals("get");
|
||||||
accessor = typeMapper.mapToCallableMethod((PsiMethod) declaration);
|
|
||||||
}
|
if(isGetter) {
|
||||||
else if (declaration instanceof JetNamedFunction) {
|
FunctionDescriptor setterDescriptor = bindingContext.get(BindingContext.INDEXED_LVALUE_SET, expression);
|
||||||
accessor = typeMapper.mapToCallableMethod((JetNamedFunction) declaration, null);
|
return StackValue.collectionElement(
|
||||||
|
accessor.getSignature().getReturnType(),
|
||||||
|
accessor,
|
||||||
|
setterDescriptor != null ? typeMapper.mapToCallableMethod(setterDescriptor, OwnerKind.IMPLEMENTATION) : null);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw new UnsupportedOperationException("unknown accessor type: " + declaration);
|
FunctionDescriptor getterDescriptor = bindingContext.get(BindingContext.INDEXED_LVALUE_GET, expression);
|
||||||
|
return StackValue.collectionElement(
|
||||||
|
accessor.getSignature().getArgumentTypes()[1],
|
||||||
|
getterDescriptor != null ? typeMapper.mapToCallableMethod(getterDescriptor, OwnerKind.IMPLEMENTATION) : null,
|
||||||
|
accessor);
|
||||||
}
|
}
|
||||||
boolean isGetter = accessor.getSignature().getName().equals("get");
|
|
||||||
return StackValue.collectionElement(
|
|
||||||
isGetter ? accessor.getSignature().getReturnType() : accessor.getSignature().getArgumentTypes()[1],
|
|
||||||
isGetter ? accessor : null,
|
|
||||||
isGetter ? null : accessor);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
fun box () : String {
|
||||||
|
val s = java.util.ArrayList<String>()
|
||||||
|
s.add("foo")
|
||||||
|
s[0] += "bar"
|
||||||
|
return if(s[0] == "foobar") "OK" else "fail"
|
||||||
|
}
|
||||||
@@ -96,4 +96,15 @@ public class ArrayGenTest extends CodegenTestCase {
|
|||||||
Method foo = generateFunction();
|
Method foo = generateFunction();
|
||||||
foo.invoke(null);
|
foo.invoke(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testCollectionPlusAssign () throws Exception {
|
||||||
|
blackBoxFile("regressions/kt33.jet");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testArrayPlusAssign () throws Exception {
|
||||||
|
loadText("fun box() : Int { val s = IntArray(1); s [0] = 5; s[0] += 7; return s[0] }");
|
||||||
|
System.out.println(generateToText());
|
||||||
|
Method foo = generateFunction();
|
||||||
|
assertTrue((Integer)foo.invoke(null) == 12);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user