added test for KT-238
This commit is contained in:
@@ -1262,7 +1262,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
||||
|
||||
private StackValue generateAssignmentExpression(JetBinaryExpression expression) {
|
||||
StackValue stackValue = gen(expression.getLeft());
|
||||
genToJVMStack(expression.getRight());
|
||||
gen(expression.getRight(), stackValue.type);
|
||||
stackValue.store(v);
|
||||
return StackValue.none();
|
||||
}
|
||||
@@ -1507,8 +1507,10 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
||||
throw new UnsupportedOperationException("unknown accessor type");
|
||||
}
|
||||
boolean isGetter = accessor.getSignature().getName().equals("get");
|
||||
return StackValue.collectionElement(JetTypeMapper.TYPE_OBJECT, isGetter ? accessor : null,
|
||||
isGetter ? null : accessor);
|
||||
return StackValue.collectionElement(
|
||||
isGetter ? accessor.getSignature().getReturnType() : accessor.getSignature().getArgumentTypes()[1],
|
||||
isGetter ? accessor : null,
|
||||
isGetter ? null : accessor);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -422,6 +422,7 @@ public abstract class StackValue {
|
||||
throw new UnsupportedOperationException("no getter specified");
|
||||
}
|
||||
getter.invoke(v);
|
||||
coerce(type, v);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
fun t1 () {
|
||||
val a1 = Array<String?>(1)
|
||||
a1[0] = "0" //ok
|
||||
val s = a1[0] //ok
|
||||
}
|
||||
|
||||
fun t2 () {
|
||||
val a2 = Array<Int>(1)
|
||||
a2[0] = 0 //ok
|
||||
var i = a2[0] //ok
|
||||
}
|
||||
|
||||
fun t3 () {
|
||||
val a3 = Array<Int?>(1)
|
||||
a3[0] = 0 //verify error
|
||||
var j = a3[0] //ok
|
||||
var k : Int = a3[0] ?: 5 //ok
|
||||
}
|
||||
|
||||
fun t4 () {
|
||||
val b1 = StrangeIntArray(10)
|
||||
b1[4] = 5 //ok
|
||||
var i = b1[1] //ok
|
||||
}
|
||||
|
||||
fun t5 () {
|
||||
val b2 = StrangeArray<Int>(10, 0)
|
||||
b2.set(4, 5) //ok
|
||||
b2[4] = 5 //verify error
|
||||
var i = b2.get(2) //ok
|
||||
i = b2[1] //verify error
|
||||
}
|
||||
|
||||
fun t6() {
|
||||
val b3 = StrangeArray<Int?>(10, 0)
|
||||
b3.set(5, 6) //ok
|
||||
b3[4] = 5 //verify error
|
||||
val v = b3[1] //ok
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
return "OK"
|
||||
}
|
||||
|
||||
class StrangeArray<T>(size: Int, private var defaultValue: T) {
|
||||
fun get(index: Int): T = defaultValue
|
||||
fun set(index: Int, v: T) {
|
||||
defaultValue = v
|
||||
}
|
||||
}
|
||||
|
||||
class StrangeIntArray(size: Int) {
|
||||
private var defaultValue = 0
|
||||
fun get(index: Int): Int = defaultValue
|
||||
fun set(index: Int, v: Int) {
|
||||
defaultValue = v
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package org.jetbrains.jet.codegen;
|
||||
|
||||
public class ArrayGetTestCase extends CodegenTestCase {
|
||||
public void testKt238 () throws Exception {
|
||||
blackBoxFile("regressions/kt238.jet");
|
||||
}
|
||||
}
|
||||
@@ -89,9 +89,9 @@ public abstract class CodegenTestCase extends LightCodeInsightFixtureTestCase {
|
||||
final JetNamespace namespace = jetFile.getRootNamespace();
|
||||
String fqName = NamespaceCodegen.getJVMClassName(namespace.getFQName()).replace("/", ".");
|
||||
Class<?> namespaceClass = loader.loadClass(fqName);
|
||||
Method method = namespaceClass.getMethod("box");
|
||||
return (String) method.invoke(null);
|
||||
}
|
||||
Method method = namespaceClass.getMethod("box");
|
||||
return (String) method.invoke(null);
|
||||
}
|
||||
|
||||
protected String generateToText() {
|
||||
GenerationState state = new GenerationState(getProject(), true);
|
||||
|
||||
Reference in New Issue
Block a user