Make Array<T>(size, init) a constructor of Array
It's not marked as inline, this is why 'crossinline' was added in jaggedArray.kt/jaggedDeep.kt. Will be fixed in the following commits
This commit is contained in:
@@ -3439,6 +3439,20 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
||||
public CallableDescriptor getResultingDescriptor() {
|
||||
return descriptor;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Map<TypeParameterDescriptor, KotlinType> getTypeArguments() {
|
||||
Map<TypeParameterDescriptor, KotlinType> originalArgs = super.getTypeArguments();
|
||||
if (originalArgs.isEmpty()) return originalArgs;
|
||||
|
||||
assert originalArgs.size() == 1 : "Unknown constructor called: " + originalArgs.size() + " type arguments";
|
||||
|
||||
return Collections.singletonMap(
|
||||
CollectionsKt.single(descriptor.getTypeParameters()),
|
||||
CollectionsKt.single(originalArgs.values())
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
return invokeFunction(fakeResolvedCall, StackValue.singleton(intrinsicConstructors, typeMapper));
|
||||
|
||||
+27
-21
@@ -18,9 +18,8 @@ package org.jetbrains.kotlin.resolve.calls.checkers;
|
||||
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||
import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.diagnostics.Errors;
|
||||
import org.jetbrains.kotlin.name.FqName;
|
||||
import org.jetbrains.kotlin.psi.KtExpression;
|
||||
@@ -40,24 +39,25 @@ public class ReifiedTypeParameterSubstitutionChecker implements CallChecker {
|
||||
for (Map.Entry<TypeParameterDescriptor, KotlinType> entry : typeArguments.entrySet()) {
|
||||
TypeParameterDescriptor parameter = entry.getKey();
|
||||
KotlinType argument = entry.getValue();
|
||||
ClassifierDescriptor argumentDeclarationDescription = argument.getConstructor().getDeclarationDescriptor();
|
||||
ClassifierDescriptor argumentDeclarationDescriptor = argument.getConstructor().getDeclarationDescriptor();
|
||||
|
||||
if (parameter.isReified()) {
|
||||
if (argumentDeclarationDescription instanceof TypeParameterDescriptor &&
|
||||
!((TypeParameterDescriptor) argumentDeclarationDescription).isReified()
|
||||
) {
|
||||
context.trace.report(
|
||||
Errors.TYPE_PARAMETER_AS_REIFIED.on(getElementToReport(context, parameter.getIndex()), parameter)
|
||||
);
|
||||
}
|
||||
else if (TypeUtilsKt.cannotBeReified(argument)) {
|
||||
context.trace.report(
|
||||
Errors.REIFIED_TYPE_FORBIDDEN_SUBSTITUTION.on(getElementToReport(context, parameter.getIndex()), argument));
|
||||
}
|
||||
else if (TypeUtilsKt.unsafeAsReifiedArgument(argument) && !hasPureReifiableAnnotation(parameter)) {
|
||||
context.trace.report(
|
||||
Errors.REIFIED_TYPE_UNSAFE_SUBSTITUTION.on(getElementToReport(context, parameter.getIndex()), argument));
|
||||
}
|
||||
if (!parameter.isReified() && !isTypeParameterOfKotlinArray(parameter)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (argumentDeclarationDescriptor instanceof TypeParameterDescriptor &&
|
||||
!((TypeParameterDescriptor) argumentDeclarationDescriptor).isReified()) {
|
||||
context.trace.report(
|
||||
Errors.TYPE_PARAMETER_AS_REIFIED.on(getElementToReport(context, parameter.getIndex()), parameter)
|
||||
);
|
||||
}
|
||||
else if (TypeUtilsKt.cannotBeReified(argument)) {
|
||||
context.trace.report(
|
||||
Errors.REIFIED_TYPE_FORBIDDEN_SUBSTITUTION.on(getElementToReport(context, parameter.getIndex()), argument));
|
||||
}
|
||||
else if (TypeUtilsKt.unsafeAsReifiedArgument(argument) && !hasPureReifiableAnnotation(parameter)) {
|
||||
context.trace.report(
|
||||
Errors.REIFIED_TYPE_UNSAFE_SUBSTITUTION.on(getElementToReport(context, parameter.getIndex()), argument));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -65,7 +65,13 @@ public class ReifiedTypeParameterSubstitutionChecker implements CallChecker {
|
||||
private static final FqName PURE_REIFIABLE_ANNOTATION_FQ_NAME = new FqName("kotlin.internal.PureReifiable");
|
||||
|
||||
private static boolean hasPureReifiableAnnotation(@NotNull TypeParameterDescriptor parameter) {
|
||||
return parameter.getAnnotations().hasAnnotation(PURE_REIFIABLE_ANNOTATION_FQ_NAME);
|
||||
return parameter.getAnnotations().hasAnnotation(PURE_REIFIABLE_ANNOTATION_FQ_NAME) ||
|
||||
isTypeParameterOfKotlinArray(parameter);
|
||||
}
|
||||
|
||||
private static boolean isTypeParameterOfKotlinArray(@NotNull TypeParameterDescriptor parameter) {
|
||||
DeclarationDescriptor container = parameter.getContainingDeclaration();
|
||||
return container instanceof ClassDescriptor && KotlinBuiltIns.isNonPrimitiveArray((ClassDescriptor) container);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
+9
-10
@@ -1,14 +1,5 @@
|
||||
package-fragment kotlin
|
||||
|
||||
public inline fun </*0*/ reified @kotlin.internal.PureReifiable() T> Array(/*0*/ size: kotlin.Int, /*1*/ init: kotlin.Function1<kotlin.Int, T>): kotlin.Array<T>
|
||||
public inline fun BooleanArray(/*0*/ size: kotlin.Int, /*1*/ init: kotlin.Function1<kotlin.Int, kotlin.Boolean>): kotlin.BooleanArray
|
||||
public inline fun ByteArray(/*0*/ size: kotlin.Int, /*1*/ init: kotlin.Function1<kotlin.Int, kotlin.Byte>): kotlin.ByteArray
|
||||
public inline fun CharArray(/*0*/ size: kotlin.Int, /*1*/ init: kotlin.Function1<kotlin.Int, kotlin.Char>): kotlin.CharArray
|
||||
public inline fun DoubleArray(/*0*/ size: kotlin.Int, /*1*/ init: kotlin.Function1<kotlin.Int, kotlin.Double>): kotlin.DoubleArray
|
||||
public inline fun FloatArray(/*0*/ size: kotlin.Int, /*1*/ init: kotlin.Function1<kotlin.Int, kotlin.Float>): kotlin.FloatArray
|
||||
public inline fun IntArray(/*0*/ size: kotlin.Int, /*1*/ init: kotlin.Function1<kotlin.Int, kotlin.Int>): kotlin.IntArray
|
||||
public inline fun LongArray(/*0*/ size: kotlin.Int, /*1*/ init: kotlin.Function1<kotlin.Int, kotlin.Long>): kotlin.LongArray
|
||||
public inline fun ShortArray(/*0*/ size: kotlin.Int, /*1*/ init: kotlin.Function1<kotlin.Int, kotlin.Short>): kotlin.ShortArray
|
||||
public inline fun </*0*/ reified @kotlin.internal.PureReifiable() T> arrayOf(/*0*/ vararg elements: T /*kotlin.Array<out T>*/): kotlin.Array<T>
|
||||
public fun </*0*/ reified @kotlin.internal.PureReifiable() T> arrayOfNulls(/*0*/ size: kotlin.Int): kotlin.Array<T?>
|
||||
public fun booleanArrayOf(/*0*/ vararg elements: kotlin.Boolean /*kotlin.BooleanArray*/): kotlin.BooleanArray
|
||||
@@ -31,7 +22,7 @@ public open class Any {
|
||||
}
|
||||
|
||||
public final class Array</*0*/ T> : kotlin.Cloneable {
|
||||
/*primary*/ private constructor Array</*0*/ T>()
|
||||
/*primary*/ public constructor Array</*0*/ T>(/*0*/ size: kotlin.Int, /*1*/ init: (kotlin.Int) -> T)
|
||||
public final val size: kotlin.Int
|
||||
public final fun <get-size>(): kotlin.Int
|
||||
public open override /*1*/ fun clone(): kotlin.Array<T>
|
||||
@@ -51,6 +42,7 @@ public final class Boolean : kotlin.Comparable<kotlin.Boolean> {
|
||||
|
||||
public final class BooleanArray : kotlin.Cloneable {
|
||||
/*primary*/ public constructor BooleanArray(/*0*/ size: kotlin.Int)
|
||||
public constructor BooleanArray(/*0*/ size: kotlin.Int, /*1*/ init: (kotlin.Int) -> kotlin.Boolean)
|
||||
public final val size: kotlin.Int
|
||||
public final fun <get-size>(): kotlin.Int
|
||||
public open override /*1*/ fun clone(): kotlin.BooleanArray
|
||||
@@ -124,6 +116,7 @@ public final class Byte : kotlin.Number, kotlin.Comparable<kotlin.Byte> {
|
||||
|
||||
public final class ByteArray : kotlin.Cloneable {
|
||||
/*primary*/ public constructor ByteArray(/*0*/ size: kotlin.Int)
|
||||
public constructor ByteArray(/*0*/ size: kotlin.Int, /*1*/ init: (kotlin.Int) -> kotlin.Byte)
|
||||
public final val size: kotlin.Int
|
||||
public final fun <get-size>(): kotlin.Int
|
||||
public open override /*1*/ fun clone(): kotlin.ByteArray
|
||||
@@ -168,6 +161,7 @@ public final class Char : kotlin.Comparable<kotlin.Char> {
|
||||
|
||||
public final class CharArray : kotlin.Cloneable {
|
||||
/*primary*/ public constructor CharArray(/*0*/ size: kotlin.Int)
|
||||
public constructor CharArray(/*0*/ size: kotlin.Int, /*1*/ init: (kotlin.Int) -> kotlin.Char)
|
||||
public final val size: kotlin.Int
|
||||
public final fun <get-size>(): kotlin.Int
|
||||
public open override /*1*/ fun clone(): kotlin.CharArray
|
||||
@@ -290,6 +284,7 @@ public final class Double : kotlin.Number, kotlin.Comparable<kotlin.Double> {
|
||||
|
||||
public final class DoubleArray : kotlin.Cloneable {
|
||||
/*primary*/ public constructor DoubleArray(/*0*/ size: kotlin.Int)
|
||||
public constructor DoubleArray(/*0*/ size: kotlin.Int, /*1*/ init: (kotlin.Int) -> kotlin.Double)
|
||||
public final val size: kotlin.Int
|
||||
public final fun <get-size>(): kotlin.Int
|
||||
public open override /*1*/ fun clone(): kotlin.DoubleArray
|
||||
@@ -383,6 +378,7 @@ public final class Float : kotlin.Number, kotlin.Comparable<kotlin.Float> {
|
||||
|
||||
public final class FloatArray : kotlin.Cloneable {
|
||||
/*primary*/ public constructor FloatArray(/*0*/ size: kotlin.Int)
|
||||
public constructor FloatArray(/*0*/ size: kotlin.Int, /*1*/ init: (kotlin.Int) -> kotlin.Float)
|
||||
public final val size: kotlin.Int
|
||||
public final fun <get-size>(): kotlin.Int
|
||||
public open override /*1*/ fun clone(): kotlin.FloatArray
|
||||
@@ -466,6 +462,7 @@ public final class Int : kotlin.Number, kotlin.Comparable<kotlin.Int> {
|
||||
|
||||
public final class IntArray : kotlin.Cloneable {
|
||||
/*primary*/ public constructor IntArray(/*0*/ size: kotlin.Int)
|
||||
public constructor IntArray(/*0*/ size: kotlin.Int, /*1*/ init: (kotlin.Int) -> kotlin.Int)
|
||||
public final val size: kotlin.Int
|
||||
public final fun <get-size>(): kotlin.Int
|
||||
public open override /*1*/ fun clone(): kotlin.IntArray
|
||||
@@ -546,6 +543,7 @@ public final class Long : kotlin.Number, kotlin.Comparable<kotlin.Long> {
|
||||
|
||||
public final class LongArray : kotlin.Cloneable {
|
||||
/*primary*/ public constructor LongArray(/*0*/ size: kotlin.Int)
|
||||
public constructor LongArray(/*0*/ size: kotlin.Int, /*1*/ init: (kotlin.Int) -> kotlin.Long)
|
||||
public final val size: kotlin.Int
|
||||
public final fun <get-size>(): kotlin.Int
|
||||
public open override /*1*/ fun clone(): kotlin.LongArray
|
||||
@@ -642,6 +640,7 @@ public final class Short : kotlin.Number, kotlin.Comparable<kotlin.Short> {
|
||||
|
||||
public final class ShortArray : kotlin.Cloneable {
|
||||
/*primary*/ public constructor ShortArray(/*0*/ size: kotlin.Int)
|
||||
public constructor ShortArray(/*0*/ size: kotlin.Int, /*1*/ init: (kotlin.Int) -> kotlin.Short)
|
||||
public final val size: kotlin.Int
|
||||
public final fun <get-size>(): kotlin.Int
|
||||
public open override /*1*/ fun clone(): kotlin.ShortArray
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
inline fun <reified T> jaggedArray(x: (Int, Int) -> T): Array<Array<T>> = Array(1) { i ->
|
||||
inline fun <reified T> jaggedArray(crossinline x: (Int, Int) -> T): Array<Array<T>> = Array(1) { i ->
|
||||
Array(1) { j -> x(i, j) }
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
inline fun <reified T> jaggedArray(x: (Int, Int, Int) -> T): Array<Array<Array<T>>> = Array(1) { i ->
|
||||
inline fun <reified T> jaggedArray(crossinline x: (Int, Int, Int) -> T): Array<Array<Array<T>>> = Array(1) { i ->
|
||||
Array(1) {
|
||||
j -> Array(1) { k -> x(i, j, k) }
|
||||
}
|
||||
|
||||
@@ -8,19 +8,19 @@ fun <T : Any> T?.sure() : T = this!!
|
||||
fun <E> List<*>.toArray(ar: Array<E>): Array<E> = ar
|
||||
|
||||
fun testArrays(ci: List<Int?>, cii: List<Int?>?) {
|
||||
val c1: Array<Int?> = cii.sure().toArray(<!FUNCTION_CALL_EXPECTED!><!INVISIBLE_MEMBER!>Array<!><Int?><!>)
|
||||
val c1: Array<Int?> = cii.sure().toArray(<!FUNCTION_CALL_EXPECTED!><!NO_VALUE_FOR_PARAMETER, NO_VALUE_FOR_PARAMETER!>Array<!><Int?><!>)
|
||||
|
||||
val c2: Array<Int?> = ci.toArray(<!INVISIBLE_MEMBER!>Array<!><Int?>())
|
||||
val c2: Array<Int?> = ci.toArray(Array<Int?>(<!NO_VALUE_FOR_PARAMETER, NO_VALUE_FOR_PARAMETER!>)<!>)
|
||||
|
||||
val c3 = <!INVISIBLE_MEMBER!>Array<!><Int?>()
|
||||
val c3 = Array<Int?>(<!NO_VALUE_FOR_PARAMETER, NO_VALUE_FOR_PARAMETER!>)<!>
|
||||
|
||||
val c4 = ci.toArray<Int?>(<!INVISIBLE_MEMBER!>Array<!><Int?>())
|
||||
val c4 = ci.toArray<Int?>(Array<Int?>(<!NO_VALUE_FOR_PARAMETER, NO_VALUE_FOR_PARAMETER!>)<!>)
|
||||
|
||||
val c5 = ci.toArray(<!INVISIBLE_MEMBER!>Array<!><Int?>())
|
||||
val c5 = ci.toArray(Array<Int?>(<!NO_VALUE_FOR_PARAMETER, NO_VALUE_FOR_PARAMETER!>)<!>)
|
||||
|
||||
checkSubtype<Array<Int?>>(c1)
|
||||
checkSubtype<Array<Int?>>(c2)
|
||||
checkSubtype<Array<Int?>>(c3)
|
||||
checkSubtype<Array<Int?>>(c4)
|
||||
checkSubtype<Array<Int?>>(c5)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user