Processing vararg flag of parameter for primitives and wrappers.

#KT-2776 fixed
This commit is contained in:
Evgeny Gerashchenko
2012-11-28 12:55:21 +04:00
parent 6375ea89a0
commit 88bf3d9298
16 changed files with 202 additions and 8 deletions
@@ -240,19 +240,17 @@ public class SignaturesPropagationData {
}
if (someSupersVararg && originalVarargElementType == null) {
assert KotlinBuiltIns.getInstance().isArray(originalType);
assert isArrayType(originalType);
// convert to vararg; replace Array<out Foo>? with Array<Foo>
JetType varargElementType = KotlinBuiltIns.getInstance().getArrayElementType(originalType);
return new VarargCheckResult(KotlinBuiltIns.getInstance().getArrayType(varargElementType), true);
return new VarargCheckResult(getArrayType(varargElementType, Variance.INVARIANT), true);
}
else if (someSupersNotVararg && originalVarargElementType != null) {
assert KotlinBuiltIns.getInstance().isArray(originalType);
assert isArrayType(originalType);
// convert to non-vararg; replace Array<Foo> with Array<out Foo>?
return new VarargCheckResult(
TypeUtils.makeNullable(KotlinBuiltIns.getInstance().getArrayType(Variance.OUT_VARIANCE, originalVarargElementType)),
false);
return new VarargCheckResult(TypeUtils.makeNullable(getArrayType(originalVarargElementType, Variance.OUT_VARIANCE)), false);
}
return new VarargCheckResult(originalType, originalVarargElementType != null);
@@ -521,6 +519,23 @@ public class SignaturesPropagationData {
return classifier;
}
private static boolean isArrayType(@NotNull JetType type) {
KotlinBuiltIns builtIns = KotlinBuiltIns.getInstance();
return builtIns.isArray(type) || builtIns.isPrimitiveArray(type);
}
@NotNull
private static JetType getArrayType(@NotNull JetType elementType, @NotNull Variance projectionKind) {
KotlinBuiltIns builtIns = KotlinBuiltIns.getInstance();
JetType primitiveArrayType = builtIns.getPrimitiveArrayJetTypeByPrimitiveJetType(elementType);
if (primitiveArrayType != null) {
return primitiveArrayType;
}
else {
return builtIns.getArrayType(projectionKind, elementType);
}
}
private static class VarargCheckResult {
public final JetType parameterType;
public final boolean isVararg;