KT-503 test. Never use asm.Type.getElementType()
This commit is contained in:
@@ -1295,7 +1295,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
|||||||
|
|
||||||
Type type = typeMapper.mapType(outType);
|
Type type = typeMapper.mapType(outType);
|
||||||
assert type.getSort() == Type.ARRAY;
|
assert type.getSort() == Type.ARRAY;
|
||||||
Type elementType = type.getElementType();
|
Type elementType = JetTypeMapper.correctElementType(type);
|
||||||
int size = valueArgument.getArgumentExpressions().size();
|
int size = valueArgument.getArgumentExpressions().size();
|
||||||
|
|
||||||
v.iconst(valueArgument.getArgumentExpressions().size());
|
v.iconst(valueArgument.getArgumentExpressions().size());
|
||||||
@@ -2032,7 +2032,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
|||||||
else {
|
else {
|
||||||
Type type = typeMapper.mapType(arrayType, OwnerKind.IMPLEMENTATION);
|
Type type = typeMapper.mapType(arrayType, OwnerKind.IMPLEMENTATION);
|
||||||
gen(args.get(0).getArgumentExpression(), Type.INT_TYPE);
|
gen(args.get(0).getArgumentExpression(), Type.INT_TYPE);
|
||||||
v.newarray(type.getElementType());
|
v.newarray(JetTypeMapper.correctElementType(type));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(args.size() == 2) {
|
if(args.size() == 2) {
|
||||||
@@ -2092,7 +2092,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
|||||||
return StackValue.arrayElement(notBoxed, true);
|
return StackValue.arrayElement(notBoxed, true);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return StackValue.arrayElement(arrayType.getElementType(), false);
|
return StackValue.arrayElement(JetTypeMapper.correctElementType(arrayType), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
@@ -121,6 +121,12 @@ public class JetTypeMapper {
|
|||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Type correctElementType(Type type) {
|
||||||
|
String internalName = type.getInternalName();
|
||||||
|
assert internalName.charAt(0) == '[';
|
||||||
|
return Type.getType(internalName.substring(1));
|
||||||
|
}
|
||||||
|
|
||||||
public String getOwner(DeclarationDescriptor descriptor, OwnerKind kind) {
|
public String getOwner(DeclarationDescriptor descriptor, OwnerKind kind) {
|
||||||
String owner;
|
String owner;
|
||||||
DeclarationDescriptor containingDeclaration = descriptor.getContainingDeclaration();
|
DeclarationDescriptor containingDeclaration = descriptor.getContainingDeclaration();
|
||||||
|
|||||||
@@ -162,7 +162,7 @@ public class NamespaceCodegen {
|
|||||||
v.aconst(jvmType);
|
v.aconst(jvmType);
|
||||||
v.iconst(jetType.isNullable() ? 1 : 0);
|
v.iconst(jetType.isNullable() ? 1 : 0);
|
||||||
List<TypeProjection> arguments = jetType.getArguments();
|
List<TypeProjection> arguments = jetType.getArguments();
|
||||||
if (arguments.size() > 0 && !(jvmType.getSort() == Type.ARRAY && jvmType.getElementType().getSort() != Type.OBJECT)) {
|
if (arguments.size() > 0 && !(jvmType.getSort() == Type.ARRAY && JetTypeMapper.correctElementType(jvmType).getSort() != Type.OBJECT)) {
|
||||||
v.iconst(arguments.size());
|
v.iconst(arguments.size());
|
||||||
v.newarray(JetTypeMapper.TYPE_TYPEINFOPROJECTION);
|
v.newarray(JetTypeMapper.TYPE_TYPEINFOPROJECTION);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
fun iarr(vararg a : Int) = a
|
||||||
|
fun <T> array(vararg a : T) = a
|
||||||
|
|
||||||
|
fun box() : String {
|
||||||
|
val tests = array<IntArray>(
|
||||||
|
iarr(6, 5, 4, 3, 2, 1),
|
||||||
|
iarr(1, 2),
|
||||||
|
iarr(1, 2, 3),
|
||||||
|
iarr(1, 2, 3, 4),
|
||||||
|
iarr(1)
|
||||||
|
)
|
||||||
|
|
||||||
|
var n = 0
|
||||||
|
|
||||||
|
try {
|
||||||
|
var i = 0
|
||||||
|
while (true) {
|
||||||
|
if (thirdElementIsThree(tests[i++]))
|
||||||
|
n++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (e : ArrayIndexOutOfBoundsException) {
|
||||||
|
// No more tests to process
|
||||||
|
}
|
||||||
|
System.out?.println(n)
|
||||||
|
return if(n == 2) "OK" else "fail"
|
||||||
|
}
|
||||||
|
|
||||||
|
fun thirdElementIsThree(a : IntArray) =
|
||||||
|
// Problematic code does not compile
|
||||||
|
// a.size >= 3 & a[2] == 3
|
||||||
|
a.size >= 3 && a[2] == 3
|
||||||
@@ -166,4 +166,8 @@ public class ArrayGenTest extends CodegenTestCase {
|
|||||||
Method foo = generateFunction("box");
|
Method foo = generateFunction("box");
|
||||||
assertTrue((Integer)foo.invoke(null) == 10);
|
assertTrue((Integer)foo.invoke(null) == 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testKt503() {
|
||||||
|
blackBoxFile("regressions/kt503.jet");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user