Made vararg parameters have Array<out T> type
instead of simply Array<T> #KT-1638 Fixed #KT-2163 Fixed #KT-3213 Fixed #KT-4172 Fixed #KT-5534 Fixed
This commit is contained in:
@@ -58,6 +58,7 @@ import org.jetbrains.jet.lang.resolve.java.jvmSignature.JvmMethodParameterSignat
|
|||||||
import org.jetbrains.jet.lang.resolve.java.jvmSignature.JvmMethodSignature;
|
import org.jetbrains.jet.lang.resolve.java.jvmSignature.JvmMethodSignature;
|
||||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||||
import org.jetbrains.jet.lang.types.JetType;
|
import org.jetbrains.jet.lang.types.JetType;
|
||||||
|
import org.jetbrains.jet.lang.types.Variance;
|
||||||
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
||||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||||
import org.jetbrains.jet.lexer.JetTokens;
|
import org.jetbrains.jet.lexer.JetTokens;
|
||||||
@@ -78,6 +79,7 @@ import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.*;
|
|||||||
import static org.jetbrains.jet.lang.resolve.java.JvmAnnotationNames.KotlinSyntheticClass;
|
import static org.jetbrains.jet.lang.resolve.java.JvmAnnotationNames.KotlinSyntheticClass;
|
||||||
import static org.jetbrains.jet.lang.resolve.java.diagnostics.DiagnosticsPackage.*;
|
import static org.jetbrains.jet.lang.resolve.java.diagnostics.DiagnosticsPackage.*;
|
||||||
import static org.jetbrains.jet.lang.resolve.java.diagnostics.JvmDeclarationOrigin.NO_ORIGIN;
|
import static org.jetbrains.jet.lang.resolve.java.diagnostics.JvmDeclarationOrigin.NO_ORIGIN;
|
||||||
|
import static org.jetbrains.jet.lang.types.Variance.INVARIANT;
|
||||||
import static org.jetbrains.org.objectweb.asm.Opcodes.*;
|
import static org.jetbrains.org.objectweb.asm.Opcodes.*;
|
||||||
|
|
||||||
public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||||
@@ -460,12 +462,15 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
JetType arrayType = KotlinBuiltIns.getInstance().getArrayType(function.getTypeParameters().get(0).getDefaultType());
|
|
||||||
JetType returnType = function.getReturnType();
|
JetType returnType = function.getReturnType();
|
||||||
assert returnType != null : function.toString();
|
assert returnType != null : function.toString();
|
||||||
JetType paramType = function.getValueParameters().get(0).getType();
|
JetType paramType = function.getValueParameters().get(0).getType();
|
||||||
if (JetTypeChecker.DEFAULT.equalTypes(arrayType, returnType) && JetTypeChecker.DEFAULT.equalTypes(arrayType, paramType)) {
|
if (KotlinBuiltIns.isArray(returnType) && KotlinBuiltIns.isArray(paramType)) {
|
||||||
return true;
|
JetType elementType = function.getTypeParameters().get(0).getDefaultType();
|
||||||
|
if (JetTypeChecker.DEFAULT.equalTypes(elementType, KotlinBuiltIns.getInstance().getArrayElementType(returnType))
|
||||||
|
&& JetTypeChecker.DEFAULT.equalTypes(elementType, KotlinBuiltIns.getInstance().getArrayElementType(paramType))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -818,7 +823,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void generateEnumValuesMethod() {
|
private void generateEnumValuesMethod() {
|
||||||
Type type = typeMapper.mapType(KotlinBuiltIns.getInstance().getArrayType(descriptor.getDefaultType()));
|
Type type = typeMapper.mapType(KotlinBuiltIns.getInstance().getArrayType(INVARIANT, descriptor.getDefaultType()));
|
||||||
|
|
||||||
FunctionDescriptor valuesFunction =
|
FunctionDescriptor valuesFunction =
|
||||||
KotlinPackage.single(descriptor.getStaticScope().getFunctions(ENUM_VALUES), new Function1<FunctionDescriptor, Boolean>() {
|
KotlinPackage.single(descriptor.getStaticScope().getFunctions(ENUM_VALUES), new Function1<FunctionDescriptor, Boolean>() {
|
||||||
@@ -1554,7 +1559,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
ExpressionCodegen codegen = createOrGetClInitCodegen();
|
ExpressionCodegen codegen = createOrGetClInitCodegen();
|
||||||
InstructionAdapter iv = codegen.v;
|
InstructionAdapter iv = codegen.v;
|
||||||
|
|
||||||
Type arrayAsmType = typeMapper.mapType(KotlinBuiltIns.getInstance().getArrayType(descriptor.getDefaultType()));
|
Type arrayAsmType = typeMapper.mapType(KotlinBuiltIns.getInstance().getArrayType(INVARIANT, descriptor.getDefaultType()));
|
||||||
v.newField(OtherOrigin(myClass), ACC_PRIVATE | ACC_STATIC | ACC_FINAL | ACC_SYNTHETIC, ENUM_VALUES_FIELD_NAME,
|
v.newField(OtherOrigin(myClass), ACC_PRIVATE | ACC_STATIC | ACC_FINAL | ACC_SYNTHETIC, ENUM_VALUES_FIELD_NAME,
|
||||||
arrayAsmType.getDescriptor(), null, null);
|
arrayAsmType.getDescriptor(), null, null);
|
||||||
|
|
||||||
|
|||||||
@@ -19,11 +19,14 @@ package org.jetbrains.jet.cli.jvm.compiler;
|
|||||||
import org.jetbrains.jet.lang.resolve.AnalyzerScriptParameter;
|
import org.jetbrains.jet.lang.resolve.AnalyzerScriptParameter;
|
||||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||||
import org.jetbrains.jet.lang.types.JetType;
|
import org.jetbrains.jet.lang.types.JetType;
|
||||||
|
import org.jetbrains.jet.lang.types.Variance;
|
||||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.jetbrains.jet.lang.types.Variance.INVARIANT;
|
||||||
|
|
||||||
public class CommandLineScriptUtils {
|
public class CommandLineScriptUtils {
|
||||||
private static final Name ARGS_NAME = Name.identifier("args");
|
private static final Name ARGS_NAME = Name.identifier("args");
|
||||||
|
|
||||||
@@ -31,7 +34,7 @@ public class CommandLineScriptUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static List<AnalyzerScriptParameter> scriptParameters() {
|
public static List<AnalyzerScriptParameter> scriptParameters() {
|
||||||
JetType arrayOfStrings = KotlinBuiltIns.getInstance().getArrayType(KotlinBuiltIns.getInstance().getStringType());
|
JetType arrayOfStrings = KotlinBuiltIns.getInstance().getArrayType(INVARIANT, KotlinBuiltIns.getInstance().getStringType());
|
||||||
AnalyzerScriptParameter argsParameter = new AnalyzerScriptParameter(ARGS_NAME, arrayOfStrings);
|
AnalyzerScriptParameter argsParameter = new AnalyzerScriptParameter(ARGS_NAME, arrayOfStrings);
|
||||||
return Collections.singletonList(argsParameter);
|
return Collections.singletonList(argsParameter);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -215,7 +215,7 @@ public class AlternativeMethodSignatureData extends ElementAlternativeSignatureD
|
|||||||
|
|
||||||
alternativeVarargElementType = TypeTransformingVisitor.computeType(alternativeTypeElement, originalParamVarargElementType,
|
alternativeVarargElementType = TypeTransformingVisitor.computeType(alternativeTypeElement, originalParamVarargElementType,
|
||||||
originalToAltTypeParameters, MEMBER_SIGNATURE_CONTRAVARIANT);
|
originalToAltTypeParameters, MEMBER_SIGNATURE_CONTRAVARIANT);
|
||||||
alternativeType = KotlinBuiltIns.getInstance().getArrayType(alternativeVarargElementType);
|
alternativeType = KotlinBuiltIns.getInstance().getArrayType(Variance.OUT_VARIANCE, alternativeVarargElementType);
|
||||||
}
|
}
|
||||||
|
|
||||||
Name altName = annotationValueParameter.getNameAsName();
|
Name altName = annotationValueParameter.getNameAsName();
|
||||||
|
|||||||
+3
-3
@@ -50,6 +50,7 @@ import java.util.*;
|
|||||||
import static org.jetbrains.jet.lang.resolve.DescriptorUtils.getFqName;
|
import static org.jetbrains.jet.lang.resolve.DescriptorUtils.getFqName;
|
||||||
import static org.jetbrains.jet.lang.resolve.java.resolver.TypeUsage.*;
|
import static org.jetbrains.jet.lang.resolve.java.resolver.TypeUsage.*;
|
||||||
import static org.jetbrains.jet.lang.types.Variance.INVARIANT;
|
import static org.jetbrains.jet.lang.types.Variance.INVARIANT;
|
||||||
|
import static org.jetbrains.jet.lang.types.Variance.OUT_VARIANCE;
|
||||||
|
|
||||||
public class SignaturesPropagationData {
|
public class SignaturesPropagationData {
|
||||||
|
|
||||||
@@ -368,6 +369,7 @@ public class SignaturesPropagationData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
KotlinBuiltIns builtIns = KotlinBuiltIns.getInstance();
|
KotlinBuiltIns builtIns = KotlinBuiltIns.getInstance();
|
||||||
|
// todo simplify (with respect to platform types)
|
||||||
if (someSupersVararg && originalVarargElementType == null) {
|
if (someSupersVararg && originalVarargElementType == null) {
|
||||||
// convert to vararg
|
// convert to vararg
|
||||||
|
|
||||||
@@ -393,10 +395,8 @@ public class SignaturesPropagationData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// replace Array<Foo> with Array<out Foo>?
|
// replace Array<Foo> with Array<out Foo>?
|
||||||
return new VarargCheckResult(TypeUtils.makeNullable(builtIns.getArrayType(Variance.OUT_VARIANCE, originalVarargElementType)),
|
return new VarargCheckResult(TypeUtils.makeNullable(builtIns.getArrayType(OUT_VARIANCE, originalVarargElementType)), false);
|
||||||
false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new VarargCheckResult(originalType, originalVarargElementType != null);
|
return new VarargCheckResult(originalType, originalVarargElementType != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -46,11 +46,11 @@ import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
|||||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue;
|
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue;
|
||||||
import org.jetbrains.jet.lang.types.ErrorUtils;
|
import org.jetbrains.jet.lang.types.ErrorUtils;
|
||||||
import org.jetbrains.jet.lang.types.JetType;
|
import org.jetbrains.jet.lang.types.JetType;
|
||||||
|
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
||||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||||
import org.jetbrains.jet.storage.StorageManager;
|
import org.jetbrains.jet.storage.StorageManager;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -58,6 +58,7 @@ import java.util.Map;
|
|||||||
import static org.jetbrains.jet.lang.diagnostics.Errors.NOT_AN_ANNOTATION_CLASS;
|
import static org.jetbrains.jet.lang.diagnostics.Errors.NOT_AN_ANNOTATION_CLASS;
|
||||||
import static org.jetbrains.jet.lang.resolve.BindingContext.ANNOTATION_DESCRIPTOR_TO_PSI_ELEMENT;
|
import static org.jetbrains.jet.lang.resolve.BindingContext.ANNOTATION_DESCRIPTOR_TO_PSI_ELEMENT;
|
||||||
import static org.jetbrains.jet.lang.types.TypeUtils.NO_EXPECTED_TYPE;
|
import static org.jetbrains.jet.lang.types.TypeUtils.NO_EXPECTED_TYPE;
|
||||||
|
import static org.jetbrains.jet.lang.types.Variance.OUT_VARIANCE;
|
||||||
|
|
||||||
public class AnnotationResolver {
|
public class AnnotationResolver {
|
||||||
|
|
||||||
@@ -244,9 +245,8 @@ public class AnnotationResolver {
|
|||||||
) {
|
) {
|
||||||
JetType varargElementType = parameterDescriptor.getVarargElementType();
|
JetType varargElementType = parameterDescriptor.getVarargElementType();
|
||||||
boolean argumentsAsVararg = varargElementType != null && !hasSpread(resolvedArgument);
|
boolean argumentsAsVararg = varargElementType != null && !hasSpread(resolvedArgument);
|
||||||
List<CompileTimeConstant<?>> constants = resolveValueArguments(resolvedArgument,
|
List<CompileTimeConstant<?>> constants = resolveValueArguments(
|
||||||
argumentsAsVararg ? varargElementType : parameterDescriptor.getType(),
|
resolvedArgument, argumentsAsVararg ? varargElementType : parameterDescriptor.getType(), trace);
|
||||||
trace);
|
|
||||||
|
|
||||||
if (argumentsAsVararg) {
|
if (argumentsAsVararg) {
|
||||||
|
|
||||||
@@ -259,9 +259,10 @@ public class AnnotationResolver {
|
|||||||
|
|
||||||
JetType arrayType = KotlinBuiltIns.getInstance().getPrimitiveArrayJetTypeByPrimitiveJetType(varargElementType);
|
JetType arrayType = KotlinBuiltIns.getInstance().getPrimitiveArrayJetTypeByPrimitiveJetType(varargElementType);
|
||||||
if (arrayType == null) {
|
if (arrayType == null) {
|
||||||
arrayType = KotlinBuiltIns.getInstance().getArrayType(varargElementType);
|
arrayType = KotlinBuiltIns.getInstance().getArrayType(OUT_VARIANCE, varargElementType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//todo use parameterDescriptor.getType() instead of arrayType
|
||||||
return new ArrayValue(constants, arrayType, true, usesVariableAsConstant);
|
return new ArrayValue(constants, arrayType, true, usesVariableAsConstant);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -277,7 +278,7 @@ public class AnnotationResolver {
|
|||||||
) {
|
) {
|
||||||
JetType expressionType = trace.get(BindingContext.EXPRESSION_TYPE, argumentExpression);
|
JetType expressionType = trace.get(BindingContext.EXPRESSION_TYPE, argumentExpression);
|
||||||
|
|
||||||
if (expressionType == null || !expressionType.equals(expectedType)) {
|
if (expressionType == null || !JetTypeChecker.DEFAULT.isSubtypeOf(expressionType, expectedType)) {
|
||||||
// TYPE_MISMATCH should be reported otherwise
|
// TYPE_MISMATCH should be reported otherwise
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -588,7 +588,7 @@ public class DescriptorResolver {
|
|||||||
if (primitiveArrayType != null) {
|
if (primitiveArrayType != null) {
|
||||||
return primitiveArrayType;
|
return primitiveArrayType;
|
||||||
}
|
}
|
||||||
return builtIns.getArrayType(Variance.INVARIANT, elementType);
|
return builtIns.getArrayType(Variance.OUT_VARIANCE, elementType);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<TypeParameterDescriptorImpl> resolveTypeParametersForCallableDescriptor(
|
public List<TypeParameterDescriptorImpl> resolveTypeParametersForCallableDescriptor(
|
||||||
|
|||||||
+2
-3
@@ -26,8 +26,7 @@ import org.jetbrains.jet.lang.psi.JetExpression;
|
|||||||
import org.jetbrains.jet.lang.resolve.calls.context.BasicCallResolutionContext;
|
import org.jetbrains.jet.lang.resolve.calls.context.BasicCallResolutionContext;
|
||||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
||||||
import org.jetbrains.jet.lang.types.JetType;
|
import org.jetbrains.jet.lang.types.JetType;
|
||||||
import org.jetbrains.jet.lang.types.TypesPackage;
|
import org.jetbrains.jet.lang.types.typeUtil.TypeUtilPackage;
|
||||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -50,7 +49,7 @@ public class ReifiedTypeParameterSubstitutionCheck implements CallResolverExtens
|
|||||||
Errors.TYPE_PARAMETER_AS_REIFIED.on(getCallElement(context), parameter)
|
Errors.TYPE_PARAMETER_AS_REIFIED.on(getCallElement(context), parameter)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else if (KotlinBuiltIns.isNothingOrNullableNothing(argument) || TypesPackage.isDynamic(argument)) {
|
else if (TypeUtilPackage.cannotBeReified(argument)) {
|
||||||
context.trace.report(Errors.REIFIED_TYPE_FORBIDDEN_SUBSTITUTION.on(getCallElement(context), argument));
|
context.trace.report(Errors.REIFIED_TYPE_FORBIDDEN_SUBSTITUTION.on(getCallElement(context), argument));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
fun box(): String {
|
||||||
|
main(array())
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
|
|
||||||
|
fun main(args: Array<String>) {
|
||||||
|
D.foo(array())
|
||||||
|
}
|
||||||
|
|
||||||
|
object D {
|
||||||
|
fun foo(array: Array<out String>) = array
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fun <reified T> array(vararg t : T) : Array<T> = t as Array<T>
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
kotlin.inline() internal fun </*0*/ reified T> array(/*0*/ vararg t: T /*kotlin.Array<out T>*/): kotlin.Array<T>
|
||||||
|
internal fun box(): kotlin.String
|
||||||
|
internal fun main(/*0*/ args: kotlin.Array<kotlin.String>): kotlin.Unit
|
||||||
|
|
||||||
|
internal object D {
|
||||||
|
private constructor D()
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
internal final fun foo(/*0*/ array: kotlin.Array<out kotlin.String>): kotlin.Array<out kotlin.String>
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
|
||||||
|
public class object <class-object-for-D> : D {
|
||||||
|
private constructor <class-object-for-D>()
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
internal final override /*1*/ /*fake_override*/ fun foo(/*0*/ array: kotlin.Array<out kotlin.String>): kotlin.Array<out kotlin.String>
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
fun <T> Array<T>?.get(i : Int?) = this!!.get(i!!)
|
fun <T> Array<T>?.get(i : Int?) = this!!.get(i!!)
|
||||||
fun <T> array(vararg t : T) : Array<T> = t
|
fun <T> array(vararg t : T) : Array<T> = t as Array<T>
|
||||||
|
|
||||||
fun box() : String {
|
fun box() : String {
|
||||||
val a : Array<String>? = array<String>("Str", "Str2")
|
val a : Array<String>? = array<String>("Str", "Str2")
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ fun fool(vararg a : Long) : LongArray = a
|
|||||||
fun food(vararg a : Double) : DoubleArray = a
|
fun food(vararg a : Double) : DoubleArray = a
|
||||||
fun foof(vararg a : Float) : FloatArray = a
|
fun foof(vararg a : Float) : FloatArray = a
|
||||||
fun foob(vararg a : Boolean) : BooleanArray = a
|
fun foob(vararg a : Boolean) : BooleanArray = a
|
||||||
fun foos(vararg a : String) : Array<String> = a
|
fun foos(vararg a : String) : Array<out String> = a
|
||||||
|
|
||||||
fun test() {
|
fun test() {
|
||||||
Arrays.asList(1, 2, 3)
|
Arrays.asList(1, 2, 3)
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ fun foo() {
|
|||||||
// ---------------------
|
// ---------------------
|
||||||
// copy from kotlin util
|
// copy from kotlin util
|
||||||
|
|
||||||
fun <T> array(vararg t : T) : Array<T> = t
|
fun <T> array(vararg t : T) : Array<T> = t as Array<T>
|
||||||
|
|
||||||
fun <T, R> Array<T>.map(<!UNUSED_PARAMETER!>transform<!> : (T) -> R) : List<R> {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
|
fun <T, R> Array<T>.map(<!UNUSED_PARAMETER!>transform<!> : (T) -> R) : List<R> {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
|
||||||
|
|
||||||
|
|||||||
@@ -11,4 +11,4 @@ fun main(args: Array<String>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//from library
|
//from library
|
||||||
fun <T> array(vararg t : T) : Array<T> = t
|
fun <T> array(vararg t : T) : Array<T> = t as Array<T>
|
||||||
@@ -13,4 +13,4 @@ public fun test()
|
|||||||
|
|
||||||
//--------------------
|
//--------------------
|
||||||
|
|
||||||
fun <T> array(vararg t : T) : Array<T> = t
|
fun <T> array(vararg t : T) : Array<T> = t as Array<T>
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||||
|
|
||||||
|
fun printAll(vararg a : Any) {}
|
||||||
|
|
||||||
|
fun main(args: Array<String>) {
|
||||||
|
printAll(*args) // Shouldn't be an error
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
internal fun main(/*0*/ args: kotlin.Array<kotlin.String>): kotlin.Unit
|
||||||
|
internal fun printAll(/*0*/ vararg a: kotlin.Any /*kotlin.Array<out kotlin.Any>*/): kotlin.Unit
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
// !CHECK_TYPE
|
||||||
|
|
||||||
|
fun test(vararg a: String) {
|
||||||
|
a checkType { it : _<Array<out String>> }
|
||||||
|
|
||||||
|
foo(a) checkType { it : _<Array<out String>> }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <T> test1(vararg t: T) {
|
||||||
|
t checkType { it : _<Array<out T>> }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <T> foo(a: Array<T>): Array<T> = a
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
internal fun </*0*/ T> foo(/*0*/ a: kotlin.Array<T>): kotlin.Array<T>
|
||||||
|
internal fun test(/*0*/ vararg a: kotlin.String /*kotlin.Array<out kotlin.String>*/): kotlin.Unit
|
||||||
|
internal fun </*0*/ T> test1(/*0*/ vararg t: T /*kotlin.Array<out T>*/): kotlin.Unit
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||||
|
|
||||||
|
fun bar(vararg a: String) {}
|
||||||
|
|
||||||
|
fun test2(a: Array<String>, b: Array<out String>) {
|
||||||
|
bar(*a)
|
||||||
|
bar(*b)
|
||||||
|
bar("", *a, *b, "")
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
internal fun bar(/*0*/ vararg a: kotlin.String /*kotlin.Array<out kotlin.String>*/): kotlin.Unit
|
||||||
|
internal fun test2(/*0*/ a: kotlin.Array<kotlin.String>, /*1*/ b: kotlin.Array<out kotlin.String>): kotlin.Unit
|
||||||
+1
-1
@@ -15,7 +15,7 @@ fun foo(): Int = 1
|
|||||||
|
|
||||||
annotation class AnnJC(val i: Array<Class<*>>)
|
annotation class AnnJC(val i: Array<Class<*>>)
|
||||||
AnnJC(array(javaClass<Test>()))
|
AnnJC(array(javaClass<Test>()))
|
||||||
AnnJC(array(iJC))
|
AnnJC(array(<!ANNOTATION_PARAMETER_MUST_BE_CLASS_LITERAL!>iJC<!>))
|
||||||
class TestJC
|
class TestJC
|
||||||
val iJC = javaClass<Test>()
|
val iJC = javaClass<Test>()
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -18,7 +18,7 @@ fun foo(): Int = 1
|
|||||||
|
|
||||||
annotation class AnnJC(vararg val i: Class<*>)
|
annotation class AnnJC(vararg val i: Class<*>)
|
||||||
AnnJC(*array(javaClass<Test>()))
|
AnnJC(*array(javaClass<Test>()))
|
||||||
AnnJC(*array(iJC))
|
AnnJC(*array(<!ANNOTATION_PARAMETER_MUST_BE_CLASS_LITERAL!>iJC<!>))
|
||||||
class TestJC
|
class TestJC
|
||||||
val iJC = javaClass<Test>()
|
val iJC = javaClass<Test>()
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
// !CHECK_TYPE
|
||||||
|
|
||||||
|
fun test(a: Array<out String>) {
|
||||||
|
val b = a.toList()
|
||||||
|
|
||||||
|
b checkType { it : _<List<String>> }
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
internal fun test(/*0*/ a: kotlin.Array<out kotlin.String>): kotlin.Unit
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
// FILE: A.java
|
||||||
|
public class A {
|
||||||
|
public static void main(String[] args) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: 1.kt
|
||||||
|
fun main(args: Array<String>) {
|
||||||
|
A.main(array())
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
internal fun main(/*0*/ args: kotlin.Array<kotlin.String>): kotlin.Unit
|
||||||
|
|
||||||
|
public open class A {
|
||||||
|
public constructor A()
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
|
||||||
|
// Static members
|
||||||
|
public open fun main(/*0*/ args: kotlin.Array<(out) kotlin.String!>!): kotlin.Unit
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
fun test() {
|
||||||
|
val p: Array<String> = array("a")
|
||||||
|
foo(*p)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun foo(vararg a: String?) = a
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
internal fun foo(/*0*/ vararg a: kotlin.String? /*kotlin.Array<out kotlin.String?>*/): kotlin.Array<out kotlin.String?>
|
||||||
|
internal fun test(): kotlin.Unit
|
||||||
@@ -4899,7 +4899,7 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
|||||||
|
|
||||||
@TestMetadata("compiler/testData/diagnostics/tests/inference")
|
@TestMetadata("compiler/testData/diagnostics/tests/inference")
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@InnerTestClasses({Inference.CapturedTypes.class, Inference.Constraints.class, Inference.NestedCalls.class, Inference.Regressions.class, Inference.ReportingImprovements.class, Inference.Substitutions.class, Inference.UpperBounds.class, Inference.Varargs.class})
|
@InnerTestClasses({Inference.CapturedTypes.class, Inference.Constraints.class, Inference.NestedCalls.class, Inference.Regressions.class, Inference.ReportingImprovements.class, Inference.Substitutions.class, Inference.UpperBounds.class})
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
public static class Inference extends AbstractJetDiagnosticsTest {
|
public static class Inference extends AbstractJetDiagnosticsTest {
|
||||||
public void testAllFilesPresentInInference() throws Exception {
|
public void testAllFilesPresentInInference() throws Exception {
|
||||||
@@ -5106,6 +5106,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("captureTypeOnlyOnTopLevel.kt")
|
||||||
|
public void testCaptureTypeOnlyOnTopLevel() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/capturedTypes/captureTypeOnlyOnTopLevel.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("capturedType.kt")
|
@TestMetadata("capturedType.kt")
|
||||||
public void testCapturedType() throws Exception {
|
public void testCapturedType() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/capturedTypes/capturedType.kt");
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/capturedTypes/capturedType.kt");
|
||||||
@@ -5129,12 +5135,6 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
|||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/capturedTypes/kt2872.kt");
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/capturedTypes/kt2872.kt");
|
||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("captureTypeOnlyOnTopLevel.kt")
|
|
||||||
public void testCaptureTypeOnlyOnTopLevel() throws Exception {
|
|
||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/capturedTypes/captureTypeOnlyOnTopLevel.kt");
|
|
||||||
doTest(fileName);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("compiler/testData/diagnostics/tests/inference/constraints")
|
@TestMetadata("compiler/testData/diagnostics/tests/inference/constraints")
|
||||||
@@ -5640,21 +5640,6 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("compiler/testData/diagnostics/tests/inference/varargs")
|
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
|
||||||
public static class Varargs extends AbstractJetDiagnosticsTest {
|
|
||||||
public void testAllFilesPresentInVarargs() throws Exception {
|
|
||||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/tests/inference/varargs"), Pattern.compile("^(.+)\\.kt$"), true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@TestMetadata("varargsAndPair.kt")
|
|
||||||
public void testVarargsAndPair() throws Exception {
|
|
||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/varargs/varargsAndPair.kt");
|
|
||||||
doTest(fileName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("compiler/testData/diagnostics/tests/infos")
|
@TestMetadata("compiler/testData/diagnostics/tests/infos")
|
||||||
@@ -10304,6 +10289,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt2163.kt")
|
||||||
|
public void testKt2163() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/varargs/kt2163.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt422.kt")
|
@TestMetadata("kt422.kt")
|
||||||
public void testKt422() throws Exception {
|
public void testKt422() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/varargs/kt422.kt");
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/varargs/kt422.kt");
|
||||||
@@ -10345,6 +10336,24 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
|||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/varargs/varargsAndFunctionLiterals.kt");
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/varargs/varargsAndFunctionLiterals.kt");
|
||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("varargsAndOut1.kt")
|
||||||
|
public void testVarargsAndOut1() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/varargs/varargsAndOut1.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("varargsAndOut2.kt")
|
||||||
|
public void testVarargsAndOut2() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/varargs/varargsAndOut2.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("varargsAndPair.kt")
|
||||||
|
public void testVarargsAndPair() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/varargs/varargsAndPair.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("compiler/testData/diagnostics/tests/variance")
|
@TestMetadata("compiler/testData/diagnostics/tests/variance")
|
||||||
@@ -10567,7 +10576,7 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
|||||||
|
|
||||||
@TestMetadata("compiler/testData/codegen/box/diagnostics")
|
@TestMetadata("compiler/testData/codegen/box/diagnostics")
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@InnerTestClasses({Diagnostics.Functions.class})
|
@InnerTestClasses({Diagnostics.Functions.class, Diagnostics.Vararg.class})
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
public static class Diagnostics extends AbstractJetDiagnosticsTest {
|
public static class Diagnostics extends AbstractJetDiagnosticsTest {
|
||||||
public void testAllFilesPresentInDiagnostics() throws Exception {
|
public void testAllFilesPresentInDiagnostics() throws Exception {
|
||||||
@@ -10902,5 +10911,20 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("compiler/testData/codegen/box/diagnostics/vararg")
|
||||||
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
public static class Vararg extends AbstractJetDiagnosticsTest {
|
||||||
|
public void testAllFilesPresentInVararg() throws Exception {
|
||||||
|
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/diagnostics/vararg"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt4172.kt")
|
||||||
|
public void testKt4172() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/diagnostics/vararg/kt4172.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+28
-1
@@ -30,7 +30,7 @@ import java.util.regex.Pattern;
|
|||||||
@SuppressWarnings("all")
|
@SuppressWarnings("all")
|
||||||
@TestMetadata("compiler/testData/diagnostics/testsWithStdLib")
|
@TestMetadata("compiler/testData/diagnostics/testsWithStdLib")
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@InnerTestClasses({JetDiagnosticsTestWithStdLibGenerated.Annotations.class, JetDiagnosticsTestWithStdLibGenerated.CallableReference.class, JetDiagnosticsTestWithStdLibGenerated.DuplicateJvmSignature.class, JetDiagnosticsTestWithStdLibGenerated.FunctionLiterals.class, JetDiagnosticsTestWithStdLibGenerated.Inference.class, JetDiagnosticsTestWithStdLibGenerated.KotlinSignature.class, JetDiagnosticsTestWithStdLibGenerated.Reified.class, JetDiagnosticsTestWithStdLibGenerated.Resolve.class})
|
@InnerTestClasses({JetDiagnosticsTestWithStdLibGenerated.Annotations.class, JetDiagnosticsTestWithStdLibGenerated.CallableReference.class, JetDiagnosticsTestWithStdLibGenerated.DuplicateJvmSignature.class, JetDiagnosticsTestWithStdLibGenerated.FunctionLiterals.class, JetDiagnosticsTestWithStdLibGenerated.Inference.class, JetDiagnosticsTestWithStdLibGenerated.KotlinSignature.class, JetDiagnosticsTestWithStdLibGenerated.Reified.class, JetDiagnosticsTestWithStdLibGenerated.Resolve.class, JetDiagnosticsTestWithStdLibGenerated.Varargs.class})
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
public class JetDiagnosticsTestWithStdLibGenerated extends AbstractJetDiagnosticsTestWithStdLib {
|
public class JetDiagnosticsTestWithStdLibGenerated extends AbstractJetDiagnosticsTestWithStdLib {
|
||||||
public void testAllFilesPresentInTestsWithStdLib() throws Exception {
|
public void testAllFilesPresentInTestsWithStdLib() throws Exception {
|
||||||
@@ -695,4 +695,31 @@ public class JetDiagnosticsTestWithStdLibGenerated extends AbstractJetDiagnostic
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("compiler/testData/diagnostics/testsWithStdLib/varargs")
|
||||||
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
public static class Varargs extends AbstractJetDiagnosticsTestWithStdLib {
|
||||||
|
public void testAllFilesPresentInVarargs() throws Exception {
|
||||||
|
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/varargs"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt3213.kt")
|
||||||
|
public void testKt3213() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/varargs/kt3213.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt4172j.kt")
|
||||||
|
public void testKt4172j() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/varargs/kt4172j.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt5534.kt")
|
||||||
|
public void testKt5534() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/varargs/kt5534.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import org.jetbrains.jet.lang.psi.JetFile;
|
|||||||
import org.jetbrains.jet.lang.resolve.AnalyzerScriptParameter;
|
import org.jetbrains.jet.lang.resolve.AnalyzerScriptParameter;
|
||||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||||
import org.jetbrains.jet.lang.types.JetType;
|
import org.jetbrains.jet.lang.types.JetType;
|
||||||
|
import org.jetbrains.jet.lang.types.Variance;
|
||||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -138,7 +139,7 @@ public class CodegenTestFiles {
|
|||||||
}
|
}
|
||||||
else if (type.equals("kotlin.Array<kotlin.String>")) {
|
else if (type.equals("kotlin.Array<kotlin.String>")) {
|
||||||
value = valueString.split(" ");
|
value = valueString.split(" ");
|
||||||
jetType = builtIns.getArrayType(builtIns.getStringType());
|
jetType = builtIns.getArrayType(Variance.INVARIANT, builtIns.getStringType());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw new AssertionError("TODO: " + type);
|
throw new AssertionError("TODO: " + type);
|
||||||
|
|||||||
+16
-1
@@ -2606,7 +2606,7 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
|
|
||||||
@TestMetadata("compiler/testData/codegen/box/diagnostics")
|
@TestMetadata("compiler/testData/codegen/box/diagnostics")
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@InnerTestClasses({Diagnostics.Functions.class})
|
@InnerTestClasses({Diagnostics.Functions.class, Diagnostics.Vararg.class})
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
public static class Diagnostics extends AbstractBlackBoxCodegenTest {
|
public static class Diagnostics extends AbstractBlackBoxCodegenTest {
|
||||||
public void testAllFilesPresentInDiagnostics() throws Exception {
|
public void testAllFilesPresentInDiagnostics() throws Exception {
|
||||||
@@ -2941,6 +2941,21 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("compiler/testData/codegen/box/diagnostics/vararg")
|
||||||
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
public static class Vararg extends AbstractBlackBoxCodegenTest {
|
||||||
|
public void testAllFilesPresentInVararg() throws Exception {
|
||||||
|
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/diagnostics/vararg"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt4172.kt")
|
||||||
|
public void testKt4172() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/diagnostics/vararg/kt4172.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("compiler/testData/codegen/box/elvis")
|
@TestMetadata("compiler/testData/codegen/box/elvis")
|
||||||
|
|||||||
+2
-3
@@ -73,8 +73,7 @@ class LazyJavaTypeResolver(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val howArgumentTypeIsUsed = if (isVararg) MEMBER_SIGNATURE_CONTRAVARIANT else TYPE_ARGUMENT
|
val componentType = transformJavaType(javaComponentType, TYPE_ARGUMENT.toAttributes(attr.allowFlexible))
|
||||||
val componentType = transformJavaType(javaComponentType, howArgumentTypeIsUsed.toAttributes(attr.allowFlexible))
|
|
||||||
|
|
||||||
if (PLATFORM_TYPES && attr.allowFlexible) {
|
if (PLATFORM_TYPES && attr.allowFlexible) {
|
||||||
return FlexibleJavaClassifierTypeCapabilities.create(
|
return FlexibleJavaClassifierTypeCapabilities.create(
|
||||||
@@ -82,7 +81,7 @@ class LazyJavaTypeResolver(
|
|||||||
TypeUtils.makeNullable(KotlinBuiltIns.getInstance().getArrayType(OUT_VARIANCE, componentType)))
|
TypeUtils.makeNullable(KotlinBuiltIns.getInstance().getArrayType(OUT_VARIANCE, componentType)))
|
||||||
}
|
}
|
||||||
|
|
||||||
val projectionKind = if (attr.howThisTypeIsUsed == MEMBER_SIGNATURE_CONTRAVARIANT && !isVararg) OUT_VARIANCE else INVARIANT
|
val projectionKind = if (attr.howThisTypeIsUsed == MEMBER_SIGNATURE_CONTRAVARIANT || isVararg) OUT_VARIANCE else INVARIANT
|
||||||
val result = KotlinBuiltIns.getInstance().getArrayType(projectionKind, componentType)
|
val result = KotlinBuiltIns.getInstance().getArrayType(projectionKind, componentType)
|
||||||
return TypeUtils.makeNullableAsSpecified(result, !attr.isMarkedNotNull)
|
return TypeUtils.makeNullableAsSpecified(result, !attr.isMarkedNotNull)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import org.jetbrains.jet.lang.descriptors.impl.*;
|
|||||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ExtensionReceiver;
|
import org.jetbrains.jet.lang.resolve.scopes.receivers.ExtensionReceiver;
|
||||||
import org.jetbrains.jet.lang.types.JetType;
|
import org.jetbrains.jet.lang.types.JetType;
|
||||||
|
import org.jetbrains.jet.lang.types.Variance;
|
||||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -89,7 +90,7 @@ public class DescriptorFactory {
|
|||||||
CallableMemberDescriptor.Kind.SYNTHESIZED, enumClass.getSource());
|
CallableMemberDescriptor.Kind.SYNTHESIZED, enumClass.getSource());
|
||||||
return values.initialize(null, NO_RECEIVER_PARAMETER, Collections.<TypeParameterDescriptor>emptyList(),
|
return values.initialize(null, NO_RECEIVER_PARAMETER, Collections.<TypeParameterDescriptor>emptyList(),
|
||||||
Collections.<ValueParameterDescriptor>emptyList(),
|
Collections.<ValueParameterDescriptor>emptyList(),
|
||||||
KotlinBuiltIns.getInstance().getArrayType(enumClass.getDefaultType()), Modality.FINAL,
|
KotlinBuiltIns.getInstance().getArrayType(Variance.INVARIANT, enumClass.getDefaultType()), Modality.FINAL,
|
||||||
Visibilities.PUBLIC);
|
Visibilities.PUBLIC);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import org.jetbrains.jet.lang.resolve.calls.inference.TypeBounds.BoundKind.*
|
|||||||
import org.jetbrains.jet.lang.resolve.calls.inference.constraintPosition.ConstraintPosition
|
import org.jetbrains.jet.lang.resolve.calls.inference.constraintPosition.ConstraintPosition
|
||||||
import org.jetbrains.jet.utils.addIfNotNull
|
import org.jetbrains.jet.utils.addIfNotNull
|
||||||
import org.jetbrains.jet.lang.types.singleBestRepresentative
|
import org.jetbrains.jet.lang.types.singleBestRepresentative
|
||||||
|
import org.jetbrains.jet.lang.types.typeUtil.cannotBeReified
|
||||||
|
|
||||||
public class TypeBoundsImpl(
|
public class TypeBoundsImpl(
|
||||||
override val typeVariable: TypeParameterDescriptor,
|
override val typeVariable: TypeParameterDescriptor,
|
||||||
@@ -159,6 +160,10 @@ public class TypeBoundsImpl(
|
|||||||
// a captured type might be an answer
|
// a captured type might be an answer
|
||||||
if (!possibleAnswer.getConstructor().isDenotable() && !possibleAnswer.isCaptured()) return false
|
if (!possibleAnswer.getConstructor().isDenotable() && !possibleAnswer.isCaptured()) return false
|
||||||
|
|
||||||
|
// e.g. if T has a lower bound 'Nothing' and an upper bound 'String',
|
||||||
|
// by default 'Nothing' is inferred which can lead to an error for reified type variable
|
||||||
|
if (typeVariable.isReified() && possibleAnswer.cannotBeReified()) return false
|
||||||
|
|
||||||
for (bound in bounds) {
|
for (bound in bounds) {
|
||||||
when (bound.kind) {
|
when (bound.kind) {
|
||||||
LOWER_BOUND -> if (!JetTypeChecker.DEFAULT.isSubtypeOf(bound.constrainingType, possibleAnswer)) {
|
LOWER_BOUND -> if (!JetTypeChecker.DEFAULT.isSubtypeOf(bound.constrainingType, possibleAnswer)) {
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ import org.jetbrains.jet.lang.types.Flexibility
|
|||||||
import org.jetbrains.jet.lang.types.TypeConstructor
|
import org.jetbrains.jet.lang.types.TypeConstructor
|
||||||
import org.jetbrains.jet.utils.toReadOnlyList
|
import org.jetbrains.jet.utils.toReadOnlyList
|
||||||
import org.jetbrains.jet.lang.types.checker.JetTypeChecker
|
import org.jetbrains.jet.lang.types.checker.JetTypeChecker
|
||||||
|
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns
|
||||||
|
import org.jetbrains.jet.lang.types.isDynamic
|
||||||
|
|
||||||
fun JetType.getContainedTypeParameters(): Collection<TypeParameterDescriptor> {
|
fun JetType.getContainedTypeParameters(): Collection<TypeParameterDescriptor> {
|
||||||
val declarationDescriptor = getConstructor().getDeclarationDescriptor()
|
val declarationDescriptor = getConstructor().getDeclarationDescriptor()
|
||||||
@@ -62,4 +64,6 @@ public fun JetType.getContainedAndCapturedTypeParameterConstructors(): Collectio
|
|||||||
|
|
||||||
public fun JetType.isSubtypeOf(superType: JetType): Boolean = JetTypeChecker.DEFAULT.isSubtypeOf(this, superType)
|
public fun JetType.isSubtypeOf(superType: JetType): Boolean = JetTypeChecker.DEFAULT.isSubtypeOf(this, superType)
|
||||||
|
|
||||||
|
public fun JetType.cannotBeReified(): Boolean = KotlinBuiltIns.isNothingOrNullableNothing(this) || this.isDynamic()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -664,11 +664,6 @@ public class KotlinBuiltIns {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public JetType getArrayType(@NotNull JetType argument) {
|
|
||||||
return getArrayType(Variance.INVARIANT, argument);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public JetType getEnumType(@NotNull JetType argument) {
|
public JetType getEnumType(@NotNull JetType argument) {
|
||||||
Variance projectionType = Variance.INVARIANT;
|
Variance projectionType = Variance.INVARIANT;
|
||||||
|
|||||||
+3
-1
@@ -32,6 +32,7 @@ import org.jetbrains.jet.lang.descriptors.ClassDescriptor
|
|||||||
import org.jetbrains.jet.lang.resolve.name.ClassId
|
import org.jetbrains.jet.lang.resolve.name.ClassId
|
||||||
import org.jetbrains.jet.lang.types.ErrorUtils
|
import org.jetbrains.jet.lang.types.ErrorUtils
|
||||||
import org.jetbrains.jet.lang.descriptors.ClassKind
|
import org.jetbrains.jet.lang.descriptors.ClassKind
|
||||||
|
import org.jetbrains.jet.lang.types.Variance
|
||||||
|
|
||||||
public class AnnotationDeserializer(private val module: ModuleDescriptor) {
|
public class AnnotationDeserializer(private val module: ModuleDescriptor) {
|
||||||
private val builtIns: KotlinBuiltIns
|
private val builtIns: KotlinBuiltIns
|
||||||
@@ -97,7 +98,8 @@ public class AnnotationDeserializer(private val module: ModuleDescriptor) {
|
|||||||
val actualArrayType =
|
val actualArrayType =
|
||||||
if (arrayElements.isNotEmpty()) {
|
if (arrayElements.isNotEmpty()) {
|
||||||
val actualElementType = resolveArrayElementType(arrayElements.first(), nameResolver)
|
val actualElementType = resolveArrayElementType(arrayElements.first(), nameResolver)
|
||||||
builtIns.getPrimitiveArrayJetTypeByPrimitiveJetType(actualElementType) ?: builtIns.getArrayType(actualElementType)
|
builtIns.getPrimitiveArrayJetTypeByPrimitiveJetType(actualElementType) ?:
|
||||||
|
builtIns.getArrayType(Variance.INVARIANT, actualElementType)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// In the case of empty array, no element has the element type, so we fall back to the expected type.
|
// In the case of empty array, no element has the element type, so we fall back to the expected type.
|
||||||
|
|||||||
@@ -142,7 +142,8 @@ public class JetNameSuggester {
|
|||||||
else {
|
else {
|
||||||
if (jetType.getArguments().size() == 1) {
|
if (jetType.getArguments().size() == 1) {
|
||||||
JetType argument = jetType.getArguments().get(0).getType();
|
JetType argument = jetType.getArguments().get(0).getType();
|
||||||
if (typeChecker.equalTypes(builtIns.getArrayType(argument), jetType)) {
|
if ((KotlinBuiltIns.isArray(jetType) || KotlinBuiltIns.isPrimitiveArray(jetType)) &&
|
||||||
|
typeChecker.equalTypes(argument, builtIns.getArrayElementType(jetType))) {
|
||||||
if (typeChecker.equalTypes(builtIns.getBooleanType(), argument)) {
|
if (typeChecker.equalTypes(builtIns.getBooleanType(), argument)) {
|
||||||
addName(result, "booleans", validator);
|
addName(result, "booleans", validator);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import java.util.Arrays
|
|||||||
import kotlin.jvm.internal.Intrinsic
|
import kotlin.jvm.internal.Intrinsic
|
||||||
|
|
||||||
// Array "constructor"
|
// Array "constructor"
|
||||||
[Intrinsic("kotlin.arrays.array")] public fun <reified T> array(vararg t : T) : Array<T> = t
|
[Intrinsic("kotlin.arrays.array")] public fun <reified T> array(vararg t : T) : Array<T> = t as Array<T>
|
||||||
|
|
||||||
// "constructors" for primitive types array
|
// "constructors" for primitive types array
|
||||||
[Intrinsic("kotlin.arrays.array")] public fun doubleArray(vararg content : Double) : DoubleArray = content
|
[Intrinsic("kotlin.arrays.array")] public fun doubleArray(vararg content : Double) : DoubleArray = content
|
||||||
|
|||||||
Reference in New Issue
Block a user