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);
|
||||
assert type.getSort() == Type.ARRAY;
|
||||
Type elementType = type.getElementType();
|
||||
Type elementType = JetTypeMapper.correctElementType(type);
|
||||
int size = valueArgument.getArgumentExpressions().size();
|
||||
|
||||
v.iconst(valueArgument.getArgumentExpressions().size());
|
||||
@@ -1314,7 +1314,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
||||
}
|
||||
return mask;
|
||||
}
|
||||
|
||||
|
||||
private int pushMethodArguments(JetCallElement expression, List<Type> valueParameterTypes) {
|
||||
ResolvedCall<? extends CallableDescriptor> resolvedCall = bindingContext.get(BindingContext.RESOLVED_CALL, expression.getCalleeExpression());
|
||||
if(resolvedCall != null) {
|
||||
@@ -2032,7 +2032,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
||||
else {
|
||||
Type type = typeMapper.mapType(arrayType, OwnerKind.IMPLEMENTATION);
|
||||
gen(args.get(0).getArgumentExpression(), Type.INT_TYPE);
|
||||
v.newarray(type.getElementType());
|
||||
v.newarray(JetTypeMapper.correctElementType(type));
|
||||
}
|
||||
|
||||
if(args.size() == 2) {
|
||||
@@ -2092,7 +2092,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
||||
return StackValue.arrayElement(notBoxed, true);
|
||||
}
|
||||
else {
|
||||
return StackValue.arrayElement(arrayType.getElementType(), false);
|
||||
return StackValue.arrayElement(JetTypeMapper.correctElementType(arrayType), false);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -121,6 +121,12 @@ public class JetTypeMapper {
|
||||
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) {
|
||||
String owner;
|
||||
DeclarationDescriptor containingDeclaration = descriptor.getContainingDeclaration();
|
||||
|
||||
@@ -162,7 +162,7 @@ public class NamespaceCodegen {
|
||||
v.aconst(jvmType);
|
||||
v.iconst(jetType.isNullable() ? 1 : 0);
|
||||
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.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");
|
||||
assertTrue((Integer)foo.invoke(null) == 10);
|
||||
}
|
||||
|
||||
public void testKt503() {
|
||||
blackBoxFile("regressions/kt503.jet");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user