Make Array type parameter T non-reified
This commit is contained in:
+4
-1
@@ -579,6 +579,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
|
||||
TypeConstructor typeConstructor = type.getConstructor();
|
||||
ClassifierDescriptor typeDeclarationDescriptor = typeConstructor.getDeclarationDescriptor();
|
||||
boolean typeIsArray = KotlinBuiltIns.isArray(type);
|
||||
|
||||
if (typeDeclarationDescriptor instanceof ClassDescriptor) {
|
||||
List<TypeParameterDescriptor> parameters = typeConstructor.getParameters();
|
||||
@@ -586,8 +587,10 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
|
||||
Iterator<TypeProjection> typeArgumentsIterator = type.getArguments().iterator();
|
||||
for (TypeParameterDescriptor parameter : parameters) {
|
||||
if (!parameter.isReified()) return false;
|
||||
if (!typeIsArray && !parameter.isReified()) return false;
|
||||
|
||||
TypeProjection typeArgument = typeArgumentsIterator.next();
|
||||
|
||||
if (typeArgument == null) return false;
|
||||
if (typeArgument.isStarProjection()) return false;
|
||||
if (!isClassAvailableAtRuntime(typeArgument.getType(), true)) return false;
|
||||
|
||||
+2
-2
@@ -12,8 +12,8 @@ public open class Any {
|
||||
/*primary*/ public constructor Any()
|
||||
}
|
||||
|
||||
public final class Array</*0*/ reified T> : kotlin.Cloneable {
|
||||
/*primary*/ private constructor Array</*0*/ reified T>()
|
||||
public final class Array</*0*/ T> : kotlin.Cloneable {
|
||||
/*primary*/ private constructor Array</*0*/ T>()
|
||||
public open override /*1*/ fun clone(): kotlin.Array<T>
|
||||
public final operator fun get(/*0*/ index: kotlin.Int): T
|
||||
public final operator fun iterator(): kotlin.Iterator<T>
|
||||
|
||||
@@ -11,4 +11,5 @@ object D {
|
||||
fun foo(array: Array<out String>) = array
|
||||
}
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
inline fun <reified T> array(vararg t : T) : Array<T> = t as Array<T>
|
||||
@@ -1,6 +1,6 @@
|
||||
package
|
||||
|
||||
@kotlin.inline() public fun </*0*/ reified T> array(/*0*/ vararg t: T /*kotlin.Array<out T>*/): kotlin.Array<T>
|
||||
@kotlin.Suppress(names = {"UNCHECKED_CAST"}) @kotlin.inline() public fun </*0*/ reified T> array(/*0*/ vararg t: T /*kotlin.Array<out T>*/): kotlin.Array<T>
|
||||
public fun box(): kotlin.String
|
||||
public fun main(/*0*/ args: kotlin.Array<kotlin.String>): kotlin.Unit
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
fun f(x: Any) = <!UNCHECKED_CAST!>x as Array<String><!>
|
||||
@@ -0,0 +1,3 @@
|
||||
package
|
||||
|
||||
public fun f(/*0*/ x: kotlin.Any): kotlin.Array<kotlin.String>
|
||||
@@ -1 +0,0 @@
|
||||
fun f(a: Array<out Number>) = a.isArrayOf<Int>()
|
||||
@@ -1,3 +0,0 @@
|
||||
package
|
||||
|
||||
public fun f(/*0*/ a: kotlin.Array<out kotlin.Number>): kotlin.Boolean
|
||||
@@ -1,6 +1,7 @@
|
||||
// !CHECK_TYPE
|
||||
|
||||
fun foo(arr: Array<out Number>): Int {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val result = (arr as Array<Int>)[0]
|
||||
checkSubtype<Array<Int>>(<!DEBUG_INFO_SMARTCAST!>arr<!>)
|
||||
return result
|
||||
|
||||
+1
@@ -1,5 +1,6 @@
|
||||
// !CHECK_TYPE
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
fun <T> arrayOf(vararg t : T) : Array<T> = t as Array<T>
|
||||
|
||||
fun test() {
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package
|
||||
|
||||
public fun </*0*/ T> arrayOf(/*0*/ vararg t: T /*kotlin.Array<out T>*/): kotlin.Array<T>
|
||||
@kotlin.Suppress(names = {"UNCHECKED_CAST"}) public fun </*0*/ T> arrayOf(/*0*/ vararg t: T /*kotlin.Array<out T>*/): kotlin.Array<T>
|
||||
public fun test(): kotlin.Unit
|
||||
|
||||
@@ -27,6 +27,7 @@ fun foo() {
|
||||
// ---------------------
|
||||
// copy from kotlin util (but with `infix` modifier on `map`)
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
fun <T> array(vararg t : T) : Array<T> = t as Array<T>
|
||||
|
||||
infix fun <T, R> Array<T>.map(<!UNUSED_PARAMETER!>transform<!> : (T) -> R) : List<R> {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package
|
||||
|
||||
package a {
|
||||
public fun </*0*/ T> array(/*0*/ vararg t: T /*kotlin.Array<out T>*/): kotlin.Array<T>
|
||||
@kotlin.Suppress(names = {"UNCHECKED_CAST"}) public fun </*0*/ T> array(/*0*/ vararg t: T /*kotlin.Array<out T>*/): kotlin.Array<T>
|
||||
public fun foo(): kotlin.Unit
|
||||
public infix fun </*0*/ T, /*1*/ R> kotlin.Array<T>.map(/*0*/ transform: (T) -> R): kotlin.List<R>
|
||||
public infix fun </*0*/ T, /*1*/ R> kotlin.Iterable<T>.map(/*0*/ transform: (T) -> R): kotlin.List<R>
|
||||
|
||||
@@ -13,4 +13,5 @@ fun main(args: Array<String>) {
|
||||
}
|
||||
|
||||
//from library
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
fun <T> array(vararg t : T) : Array<T> = t as Array<T>
|
||||
@@ -1,6 +1,6 @@
|
||||
package
|
||||
|
||||
package n {
|
||||
public fun </*0*/ T> array(/*0*/ vararg t: T /*kotlin.Array<out T>*/): kotlin.Array<T>
|
||||
@kotlin.Suppress(names = {"UNCHECKED_CAST"}) public fun </*0*/ T> array(/*0*/ vararg t: T /*kotlin.Array<out T>*/): kotlin.Array<T>
|
||||
public fun main(/*0*/ args: kotlin.Array<kotlin.String>): kotlin.Unit
|
||||
}
|
||||
|
||||
@@ -14,5 +14,5 @@ public fun test()
|
||||
}
|
||||
|
||||
//--------------------
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
fun <T> array(vararg t : T) : Array<T> = t as Array<T>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package
|
||||
|
||||
package a {
|
||||
public fun </*0*/ T> array(/*0*/ vararg t: T /*kotlin.Array<out T>*/): kotlin.Array<T>
|
||||
@kotlin.Suppress(names = {"UNCHECKED_CAST"}) public fun </*0*/ T> array(/*0*/ vararg t: T /*kotlin.Array<out T>*/): kotlin.Array<T>
|
||||
public fun </*0*/ E> foo(/*0*/ array: kotlin.Array<E>): kotlin.Array<E>
|
||||
public fun test(): kotlin.Unit
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
fun f(a: Array<out Number>) = a.isArrayOf<Int>()
|
||||
|
||||
fun f1(a: Array<out Number>) = a is Array<*>
|
||||
|
||||
fun f2(a: Array<out Number>) = a is <!CANNOT_CHECK_FOR_ERASED!>Array<Int><!>
|
||||
@@ -0,0 +1,5 @@
|
||||
package
|
||||
|
||||
public fun f(/*0*/ a: kotlin.Array<out kotlin.Number>): kotlin.Boolean
|
||||
public fun f1(/*0*/ a: kotlin.Array<out kotlin.Number>): kotlin.Boolean
|
||||
public fun f2(/*0*/ a: kotlin.Array<out kotlin.Number>): kotlin.Boolean
|
||||
@@ -2079,6 +2079,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/tests/cast"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("AsArray.kt")
|
||||
public void testAsArray() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/cast/AsArray.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("AsErasedError.kt")
|
||||
public void testAsErasedError() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/cast/AsErasedError.kt");
|
||||
@@ -2115,12 +2121,6 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("IsArray.kt")
|
||||
public void testIsArray() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/cast/IsArray.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("IsErasedAllowForDerivedWithOneSubstitutedAndOneSameGeneric.kt")
|
||||
public void testIsErasedAllowForDerivedWithOneSubstitutedAndOneSameGeneric() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/cast/IsErasedAllowForDerivedWithOneSubstitutedAndOneSameGeneric.kt");
|
||||
@@ -2313,12 +2313,6 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("IsReified.kt")
|
||||
public void testIsReified() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/cast/IsReified.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("IsTraits.kt")
|
||||
public void testIsTraits() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/cast/IsTraits.kt");
|
||||
|
||||
+21
@@ -524,6 +524,27 @@ public class JetDiagnosticsTestWithStdLibGenerated extends AbstractJetDiagnostic
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/diagnostics/testsWithStdLib/cast")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class Cast extends AbstractJetDiagnosticsTestWithStdLib {
|
||||
public void testAllFilesPresentInCast() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/cast"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("IsArray.kt")
|
||||
public void testIsArray() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/cast/IsArray.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("IsReified.kt")
|
||||
public void testIsReified() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/cast/IsReified.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/diagnostics/testsWithStdLib/duplicateJvmSignature")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
@@ -23,7 +23,7 @@ package kotlin
|
||||
* See [Kotlin language documentation](http://kotlinlang.org/docs/reference/basic-types.html#arrays)
|
||||
* for more information on arrays.
|
||||
*/
|
||||
public class Array<reified T> private (): Cloneable {
|
||||
public class Array<T> private (): Cloneable {
|
||||
/**
|
||||
* Returns the array element at the specified [index]. This method can be called using the
|
||||
* index operator:
|
||||
|
||||
+3
-3
@@ -27,7 +27,7 @@ abstract class ReflectJavaAnnotationArgument(
|
||||
return when {
|
||||
value.javaClass.isEnumClassOrSpecializedEnumEntryClass() -> ReflectJavaEnumValueAnnotationArgument(name, value as Enum<*>)
|
||||
value is Annotation -> ReflectJavaAnnotationAsAnnotationArgument(name, value)
|
||||
value is Array<Any> -> ReflectJavaArrayAnnotationArgument(name, value)
|
||||
value is Array<*> -> ReflectJavaArrayAnnotationArgument(name, value)
|
||||
value is Class<*> -> ReflectJavaClassObjectAnnotationArgument(name, value)
|
||||
else -> ReflectJavaLiteralAnnotationArgument(name, value)
|
||||
}
|
||||
@@ -42,9 +42,9 @@ class ReflectJavaLiteralAnnotationArgument(
|
||||
|
||||
class ReflectJavaArrayAnnotationArgument(
|
||||
name: Name?,
|
||||
private val values: Array<Any>
|
||||
private val values: Array<*>
|
||||
) : ReflectJavaAnnotationArgument(name), JavaArrayAnnotationArgument {
|
||||
override fun getElements() = values.map { ReflectJavaAnnotationArgument.create(it, null) }
|
||||
override fun getElements() = values.map { ReflectJavaAnnotationArgument.create(it!!, null) }
|
||||
}
|
||||
|
||||
class ReflectJavaEnumValueAnnotationArgument(
|
||||
|
||||
Reference in New Issue
Block a user