KT-33
This commit is contained in:
@@ -1970,23 +1970,25 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
||||
}
|
||||
}
|
||||
else {
|
||||
final PsiElement declaration = BindingContextUtils.resolveToDeclarationPsiElement(bindingContext, expression);
|
||||
assert declaration != null : "No declaration found for " + expression.getText();
|
||||
final CallableMethod accessor;
|
||||
if (declaration instanceof PsiMethod) {
|
||||
accessor = typeMapper.mapToCallableMethod((PsiMethod) declaration);
|
||||
}
|
||||
else if (declaration instanceof JetNamedFunction) {
|
||||
accessor = typeMapper.mapToCallableMethod((JetNamedFunction) declaration, null);
|
||||
DeclarationDescriptor operationDescriptor = bindingContext.get(BindingContext.REFERENCE_TARGET, expression);
|
||||
CallableMethod accessor = typeMapper.mapToCallableMethod((FunctionDescriptor) operationDescriptor, OwnerKind.IMPLEMENTATION);
|
||||
|
||||
boolean isGetter = accessor.getSignature().getName().equals("get");
|
||||
|
||||
if(isGetter) {
|
||||
FunctionDescriptor setterDescriptor = bindingContext.get(BindingContext.INDEXED_LVALUE_SET, expression);
|
||||
return StackValue.collectionElement(
|
||||
accessor.getSignature().getReturnType(),
|
||||
accessor,
|
||||
setterDescriptor != null ? typeMapper.mapToCallableMethod(setterDescriptor, OwnerKind.IMPLEMENTATION) : null);
|
||||
}
|
||||
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();
|
||||
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