[FIR] Properly enhance raw Class type in java annotations
This commit is contained in:
committed by
TeamCityServer
parent
239a330ddd
commit
1a3841d66d
+6
@@ -1260,6 +1260,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
|
||||
runTest("compiler/testData/diagnostics/tests/annotations/JavaAnnotationConstructors.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("javaAnnotationWithClassArray.kt")
|
||||
public void testJavaAnnotationWithClassArray() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/annotations/javaAnnotationWithClassArray.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt1860-negative.kt")
|
||||
public void testKt1860_negative() throws Exception {
|
||||
|
||||
+6
@@ -1260,6 +1260,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
|
||||
runTest("compiler/testData/diagnostics/tests/annotations/JavaAnnotationConstructors.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("javaAnnotationWithClassArray.kt")
|
||||
public void testJavaAnnotationWithClassArray() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/annotations/javaAnnotationWithClassArray.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt1860-negative.kt")
|
||||
public void testKt1860_negative() throws Exception {
|
||||
|
||||
+6
@@ -1260,6 +1260,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
|
||||
runTest("compiler/testData/diagnostics/tests/annotations/JavaAnnotationConstructors.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("javaAnnotationWithClassArray.kt")
|
||||
public void testJavaAnnotationWithClassArray() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/annotations/javaAnnotationWithClassArray.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt1860-negative.kt")
|
||||
public void testKt1860_negative() throws Exception {
|
||||
|
||||
@@ -99,7 +99,7 @@ private fun JavaType?.toConeTypeProjection(
|
||||
is JavaClassifierType -> {
|
||||
val lowerBound = toConeKotlinTypeForFlexibleBound(session, javaTypeParameterStack, mode, attributes)
|
||||
if (mode == FirJavaTypeConversionMode.ANNOTATION_MEMBER) {
|
||||
return lowerBound // TODO: `KClass<Any>` is wrong for raw `Class`
|
||||
return lowerBound
|
||||
}
|
||||
val upperBound = toConeKotlinTypeForFlexibleBound(session, javaTypeParameterStack, mode, attributes, lowerBound)
|
||||
if (isRaw) ConeRawType(lowerBound, upperBound) else ConeFlexibleType(lowerBound, upperBound)
|
||||
@@ -171,8 +171,11 @@ private fun JavaClassifierType.toConeKotlinTypeForFlexibleBound(
|
||||
lookupTag.takeIf { lowerBound == null && mode != FirJavaTypeConversionMode.TYPE_PARAMETER_BOUND }
|
||||
?.toFirRegularClassSymbol(session)?.typeParameterSymbols
|
||||
// Given `C<T : X>`, `C` -> `C<X>..C<*>?`.
|
||||
typeParameterSymbols?.eraseToUpperBounds(session)
|
||||
?: Array(classifier.typeParameters.size) { ConeStarProjection }
|
||||
when (mode) {
|
||||
FirJavaTypeConversionMode.ANNOTATION_MEMBER -> Array(classifier.typeParameters.size) { ConeStarProjection }
|
||||
else -> typeParameterSymbols?.eraseToUpperBounds(session)
|
||||
?: Array(classifier.typeParameters.size) { ConeStarProjection }
|
||||
}
|
||||
}
|
||||
lookupTag != lowerBound?.lookupTag && typeArguments.isNotEmpty() -> {
|
||||
val typeParameterSymbols =
|
||||
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
// FIR_IDENTICAL
|
||||
// WITH_STDLIB
|
||||
// FILE: AnnRaw.java
|
||||
public @interface AnnRaw {
|
||||
Class value();
|
||||
}
|
||||
|
||||
// FILE: Ann.java
|
||||
public @interface Ann {
|
||||
Class<?> value();
|
||||
}
|
||||
|
||||
// FILE: Utils.java
|
||||
public class Utils {
|
||||
public static void foo(Class value) {}
|
||||
public static void fooRaw(Class<?> value) {}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
|
||||
class X
|
||||
|
||||
@Ann(X::class)
|
||||
@AnnRaw(X::class)
|
||||
fun test() {
|
||||
Utils.foo(X::class.java)
|
||||
Utils.fooRaw(X::class.java)
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
package
|
||||
|
||||
@Ann(value = X::class) @AnnRaw(value = X::class) public fun test(): kotlin.Unit
|
||||
|
||||
public final annotation class Ann : kotlin.Annotation {
|
||||
public constructor Ann(/*0*/ value: kotlin.reflect.KClass<*>)
|
||||
public final val value: kotlin.reflect.KClass<*>
|
||||
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
|
||||
}
|
||||
|
||||
public final annotation class AnnRaw : kotlin.Annotation {
|
||||
public constructor AnnRaw(/*0*/ value: kotlin.reflect.KClass<(raw) kotlin.Any>)
|
||||
public final val value: kotlin.reflect.KClass<(raw) kotlin.Any>
|
||||
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
|
||||
}
|
||||
|
||||
public open class Utils {
|
||||
public constructor Utils()
|
||||
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 foo(/*0*/ value: java.lang.Class<(raw) kotlin.Any!>!): kotlin.Unit
|
||||
public open fun fooRaw(/*0*/ value: java.lang.Class<*>!): kotlin.Unit
|
||||
}
|
||||
|
||||
public final class X {
|
||||
public constructor X()
|
||||
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
|
||||
}
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@ public open class ClassObjectInParamRaw : R|kotlin/Any| {
|
||||
public constructor(): R|test/ClassObjectInParamRaw|
|
||||
|
||||
public final annotation class Anno : R|kotlin/Annotation| {
|
||||
public constructor(value: R|kotlin/reflect/KClass<kotlin/Any>|, arg: R|kotlin/Array<kotlin/reflect/KClass<kotlin/Any>>|): R|test/ClassObjectInParamRaw.Anno|
|
||||
public constructor(value: R|kotlin/reflect/KClass<*>|, arg: R|kotlin/Array<kotlin/reflect/KClass<*>>|): R|test/ClassObjectInParamRaw.Anno|
|
||||
|
||||
}
|
||||
@R|test/ClassObjectInParamRaw.Anno|(value = <getClass>(<getClass>(R|ft<test/ClassObjectInParamRaw, test/ClassObjectInParamRaw?>|)), arg = <implicitArrayOf>()) public open class Nested : R|kotlin/Any| {
|
||||
|
||||
Generated
+6
@@ -1266,6 +1266,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/tests/annotations/JavaAnnotationConstructors.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("javaAnnotationWithClassArray.kt")
|
||||
public void testJavaAnnotationWithClassArray() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/annotations/javaAnnotationWithClassArray.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt1860-negative.kt")
|
||||
public void testKt1860_negative() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user