FIR: Support java array in type argument
^KT-37321 Fixed
This commit is contained in:
@@ -1,15 +0,0 @@
|
||||
// FILE: Inv.java
|
||||
|
||||
public class Inv<T> {}
|
||||
|
||||
// FILE: A.java
|
||||
|
||||
public class A {
|
||||
public static Inv<String[]> KEY = new Inv<>();
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
|
||||
fun test() {
|
||||
val key = A.KEY
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
FILE: main.kt
|
||||
public final fun test(): R|kotlin/Unit| {
|
||||
lval key: R|ft<Inv<<error>>, Inv<<error>>?>!| = Q|A|.R|/A.KEY|
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// FILE: DataKey.java
|
||||
public class DataKey<T> {}
|
||||
|
||||
// FILE: Keys.java
|
||||
public class Keys {
|
||||
public static final DataKey<String[]> X = null;
|
||||
public static final DataKey<String> Y = null;
|
||||
|
||||
public static <T> T getData(DataKey<T> key) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
fun main() {
|
||||
// Keys.X type loaded as DataKey<error>
|
||||
Keys.getData(Keys.X)[0].length
|
||||
Keys.getData(Keys.Y).length
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
FILE: main.kt
|
||||
public final fun main(): R|kotlin/Unit| {
|
||||
Q|Keys|.R|/Keys.getData|<R|ft<kotlin/Array<ft<kotlin/String, kotlin/String?>!>, kotlin/Array<out ft<kotlin/String, kotlin/String?>!>?>!|>(Q|Keys|.R|/Keys.X|).R|FakeOverride<kotlin/Array.get: R|ft<kotlin/String, kotlin/String?>!|>|(Int(0)).R|kotlin/String.length|
|
||||
Q|Keys|.R|/Keys.getData|<R|ft<kotlin/String, kotlin/String?>!|>(Q|Keys|.R|/Keys.Y|).R|kotlin/String.length|
|
||||
}
|
||||
Generated
+5
-5
@@ -1669,11 +1669,6 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/problems/javaAccessorConversion.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("javaArrayInGeneric.kt")
|
||||
public void testJavaArrayInGeneric() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/problems/javaArrayInGeneric.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("javaQualifier.kt")
|
||||
public void testJavaQualifier() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/problems/javaQualifier.kt");
|
||||
@@ -2194,6 +2189,11 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/stdlib/j+k"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
|
||||
}
|
||||
|
||||
@TestMetadata("ArrayInGenericArguments.kt")
|
||||
public void testArrayInGenericArguments() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/stdlib/j+k/ArrayInGenericArguments.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("flexibleWildcard.kt")
|
||||
public void testFlexibleWildcard() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/stdlib/j+k/flexibleWildcard.kt");
|
||||
|
||||
+5
-5
@@ -1669,11 +1669,6 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/problems/javaAccessorConversion.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("javaArrayInGeneric.kt")
|
||||
public void testJavaArrayInGeneric() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/problems/javaArrayInGeneric.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("javaQualifier.kt")
|
||||
public void testJavaQualifier() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/problems/javaQualifier.kt");
|
||||
@@ -2194,6 +2189,11 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/stdlib/j+k"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
|
||||
}
|
||||
|
||||
@TestMetadata("ArrayInGenericArguments.kt")
|
||||
public void testArrayInGenericArguments() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/stdlib/j+k/ArrayInGenericArguments.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("flexibleWildcard.kt")
|
||||
public void testFlexibleWildcard() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/stdlib/j+k/flexibleWildcard.kt");
|
||||
|
||||
compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/java/FirTypeEnhancementTestGenerated.java
Generated
+5
@@ -28,6 +28,11 @@ public class FirTypeEnhancementTestGenerated extends AbstractFirTypeEnhancementT
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/loadJava/compiledJava"), Pattern.compile("^(.+)\\.java$"), null, true);
|
||||
}
|
||||
|
||||
@TestMetadata("ArrayInGenericArguments.java")
|
||||
public void testArrayInGenericArguments() throws Exception {
|
||||
runTest("compiler/testData/loadJava/compiledJava/ArrayInGenericArguments.java");
|
||||
}
|
||||
|
||||
@TestMetadata("ArrayTypeVariance.java")
|
||||
public void testArrayTypeVariance() throws Exception {
|
||||
runTest("compiler/testData/loadJava/compiledJava/ArrayTypeVariance.java");
|
||||
|
||||
@@ -14,8 +14,8 @@ import org.jetbrains.kotlin.fir.builder.FirBuilderDsl
|
||||
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
|
||||
import org.jetbrains.kotlin.fir.declarations.FirTypeParameter
|
||||
import org.jetbrains.kotlin.fir.declarations.FirValueParameter
|
||||
import org.jetbrains.kotlin.fir.diagnostics.DiagnosticKind
|
||||
import org.jetbrains.kotlin.fir.diagnostics.ConeSimpleDiagnostic
|
||||
import org.jetbrains.kotlin.fir.diagnostics.DiagnosticKind
|
||||
import org.jetbrains.kotlin.fir.expressions.*
|
||||
import org.jetbrains.kotlin.fir.expressions.builder.*
|
||||
import org.jetbrains.kotlin.fir.java.declarations.buildJavaValueParameter
|
||||
@@ -123,20 +123,7 @@ internal fun JavaType?.toConeKotlinTypeWithoutEnhancement(
|
||||
classId.toConeKotlinType(emptyArray(), isNullable = false)
|
||||
}
|
||||
is JavaArrayType -> {
|
||||
val componentType = componentType
|
||||
if (componentType !is JavaPrimitiveType) {
|
||||
val classId = StandardClassIds.Array
|
||||
val argumentType = componentType.toConeKotlinTypeWithoutEnhancement(session, javaTypeParameterStack)
|
||||
classId.toConeFlexibleType(
|
||||
arrayOf(argumentType),
|
||||
typeArgumentsForUpper = arrayOf(ConeKotlinTypeProjectionOut(argumentType))
|
||||
)
|
||||
} else {
|
||||
val javaComponentName = componentType.type?.typeName?.asString()?.capitalize() ?: error("Array of voids")
|
||||
val classId = StandardClassIds.byName(javaComponentName + "Array")
|
||||
|
||||
classId.toConeFlexibleType(emptyArray())
|
||||
}
|
||||
toConeKotlinTypeWithoutEnhancement(session, javaTypeParameterStack)
|
||||
}
|
||||
is JavaWildcardType -> bound?.toConeKotlinTypeWithoutEnhancement(session, javaTypeParameterStack) ?: run {
|
||||
StandardClassIds.Any.toConeFlexibleType(emptyArray())
|
||||
@@ -148,6 +135,26 @@ internal fun JavaType?.toConeKotlinTypeWithoutEnhancement(
|
||||
}
|
||||
}
|
||||
|
||||
private fun JavaArrayType.toConeKotlinTypeWithoutEnhancement(
|
||||
session: FirSession,
|
||||
javaTypeParameterStack: JavaTypeParameterStack
|
||||
): ConeFlexibleType {
|
||||
val componentType = componentType
|
||||
return if (componentType !is JavaPrimitiveType) {
|
||||
val classId = StandardClassIds.Array
|
||||
val argumentType = componentType.toConeKotlinTypeWithoutEnhancement(session, javaTypeParameterStack)
|
||||
classId.toConeFlexibleType(
|
||||
arrayOf(argumentType),
|
||||
typeArgumentsForUpper = arrayOf(ConeKotlinTypeProjectionOut(argumentType))
|
||||
)
|
||||
} else {
|
||||
val javaComponentName = componentType.type?.typeName?.asString()?.capitalize() ?: error("Array of voids")
|
||||
val classId = StandardClassIds.byName(javaComponentName + "Array")
|
||||
|
||||
classId.toConeFlexibleType(emptyArray())
|
||||
}
|
||||
}
|
||||
|
||||
private fun ClassId.toConeFlexibleType(
|
||||
typeArguments: Array<ConeTypeProjection>,
|
||||
typeArgumentsForUpper: Array<ConeTypeProjection> = typeArguments
|
||||
@@ -385,6 +392,7 @@ private fun JavaType?.toConeProjectionWithoutEnhancement(
|
||||
}
|
||||
}
|
||||
is JavaClassifierType -> toConeKotlinTypeWithoutEnhancement(session, javaTypeParameterStack)
|
||||
is JavaArrayType -> toConeKotlinTypeWithoutEnhancement(session, javaTypeParameterStack)
|
||||
else -> ConeClassErrorType("Unexpected type argument: $this")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
public open class ArrayInGenericArguments : R|kotlin/Any| {
|
||||
public final static field X: R|ft<ArrayInGenericArguments.DataKey<ft<kotlin/Array<ft<kotlin/String, kotlin/String?>!>, kotlin/Array<out ft<kotlin/String, kotlin/String?>!>?>!>, ArrayInGenericArguments.DataKey<ft<kotlin/Array<ft<kotlin/String, kotlin/String?>!>, kotlin/Array<out ft<kotlin/String, kotlin/String?>!>?>!>?>!|
|
||||
|
||||
public final static field Y: R|ft<ArrayInGenericArguments.DataKey<ft<kotlin/IntArray, kotlin/IntArray?>!>, ArrayInGenericArguments.DataKey<ft<kotlin/IntArray, kotlin/IntArray?>!>?>!|
|
||||
|
||||
public final static field Z: R|ft<ArrayInGenericArguments.DataKey<out ft<kotlin/Array<ft<kotlin/CharSequence, kotlin/CharSequence?>!>, kotlin/Array<out ft<kotlin/CharSequence, kotlin/CharSequence?>!>?>!>, ArrayInGenericArguments.DataKey<out ft<kotlin/Array<ft<kotlin/CharSequence, kotlin/CharSequence?>!>, kotlin/Array<out ft<kotlin/CharSequence, kotlin/CharSequence?>!>?>!>?>!|
|
||||
|
||||
public constructor(): R|ArrayInGenericArguments|
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
public class ArrayInGenericArguments {
|
||||
public static class DataKey<T> {}
|
||||
|
||||
public static final DataKey<String[]> X = null;
|
||||
public static final DataKey<int[]> Y = null;
|
||||
public static final DataKey<? extends CharSequence[]> Z = null;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
package test
|
||||
@@ -30,6 +30,11 @@ public class LoadJavaTestGenerated extends AbstractLoadJavaTest {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/loadJava/compiledJava"), Pattern.compile("^(.+)\\.java$"), null, true);
|
||||
}
|
||||
|
||||
@TestMetadata("ArrayInGenericArguments.java")
|
||||
public void testArrayInGenericArguments() throws Exception {
|
||||
runTest("compiler/testData/loadJava/compiledJava/ArrayInGenericArguments.java");
|
||||
}
|
||||
|
||||
@TestMetadata("ArrayTypeVariance.java")
|
||||
public void testArrayTypeVariance() throws Exception {
|
||||
runTest("compiler/testData/loadJava/compiledJava/ArrayTypeVariance.java");
|
||||
|
||||
Generated
+5
@@ -28,6 +28,11 @@ public class LoadJavaWithPsiClassReadingTestGenerated extends AbstractLoadJavaWi
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/loadJava/compiledJava"), Pattern.compile("^(.+)\\.java$"), null, true);
|
||||
}
|
||||
|
||||
@TestMetadata("ArrayInGenericArguments.java")
|
||||
public void testArrayInGenericArguments() throws Exception {
|
||||
runTest("compiler/testData/loadJava/compiledJava/ArrayInGenericArguments.java");
|
||||
}
|
||||
|
||||
@TestMetadata("ArrayTypeVariance.java")
|
||||
public void testArrayTypeVariance() throws Exception {
|
||||
runTest("compiler/testData/loadJava/compiledJava/ArrayTypeVariance.java");
|
||||
|
||||
+5
@@ -31,6 +31,11 @@ public class IrLoadJavaTestGenerated extends AbstractIrLoadJavaTest {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/loadJava/compiledJava"), Pattern.compile("^(.+)\\.java$"), null, TargetBackend.JVM_IR, true);
|
||||
}
|
||||
|
||||
@TestMetadata("ArrayInGenericArguments.java")
|
||||
public void testArrayInGenericArguments() throws Exception {
|
||||
runTest("compiler/testData/loadJava/compiledJava/ArrayInGenericArguments.java");
|
||||
}
|
||||
|
||||
@TestMetadata("ArrayTypeVariance.java")
|
||||
public void testArrayTypeVariance() throws Exception {
|
||||
runTest("compiler/testData/loadJava/compiledJava/ArrayTypeVariance.java");
|
||||
|
||||
Generated
+5
@@ -30,6 +30,11 @@ public class LoadJavaUsingJavacTestGenerated extends AbstractLoadJavaUsingJavacT
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/loadJava/compiledJava"), Pattern.compile("^(.+)\\.java$"), null, true);
|
||||
}
|
||||
|
||||
@TestMetadata("ArrayInGenericArguments.java")
|
||||
public void testArrayInGenericArguments() throws Exception {
|
||||
runTest("compiler/testData/loadJava/compiledJava/ArrayInGenericArguments.java");
|
||||
}
|
||||
|
||||
@TestMetadata("ArrayTypeVariance.java")
|
||||
public void testArrayTypeVariance() throws Exception {
|
||||
runTest("compiler/testData/loadJava/compiledJava/ArrayTypeVariance.java");
|
||||
|
||||
+5
@@ -2921,6 +2921,11 @@ public class JvmRuntimeDescriptorLoaderTestGenerated extends AbstractJvmRuntimeD
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/loadJava/compiledJava"), Pattern.compile("^(.+)\\.java$"), null, true, "sam", "kotlinSignature/propagation");
|
||||
}
|
||||
|
||||
@TestMetadata("ArrayInGenericArguments.java")
|
||||
public void testArrayInGenericArguments() throws Exception {
|
||||
runTest("compiler/testData/loadJava/compiledJava/ArrayInGenericArguments.java");
|
||||
}
|
||||
|
||||
@TestMetadata("ArrayTypeVariance.java")
|
||||
public void testArrayTypeVariance() throws Exception {
|
||||
runTest("compiler/testData/loadJava/compiledJava/ArrayTypeVariance.java");
|
||||
|
||||
Reference in New Issue
Block a user