[Test] Add tests for annotations set on type usages in expect and

...actual declarations.

 MR: KT-MR-12245

^KT-60671
This commit is contained in:
Roman Efremov
2023-10-05 13:15:27 +02:00
committed by Space Team
parent fbdc64cdad
commit cb8529d65b
12 changed files with 323 additions and 17 deletions
@@ -926,6 +926,24 @@ public class FirOldFrontendMPPDiagnosticsWithLightTreeTestGenerated extends Abst
runTest("compiler/testData/diagnostics/tests/multiplatform/annotationMatching/typeParameters.kt");
}
@Test
@TestMetadata("typeUsage.kt")
public void testTypeUsage() throws Exception {
runTest("compiler/testData/diagnostics/tests/multiplatform/annotationMatching/typeUsage.kt");
}
@Test
@TestMetadata("typeUsageWithImplicitType.kt")
public void testTypeUsageWithImplicitType() throws Exception {
runTest("compiler/testData/diagnostics/tests/multiplatform/annotationMatching/typeUsageWithImplicitType.kt");
}
@Test
@TestMetadata("typeUsageWithUnresolvedReference.kt")
public void testTypeUsageWithUnresolvedReference() throws Exception {
runTest("compiler/testData/diagnostics/tests/multiplatform/annotationMatching/typeUsageWithUnresolvedReference.kt");
}
@Test
@TestMetadata("typealias.kt")
public void testTypealias() throws Exception {
@@ -926,6 +926,24 @@ public class FirOldFrontendMPPDiagnosticsWithPsiTestGenerated extends AbstractFi
runTest("compiler/testData/diagnostics/tests/multiplatform/annotationMatching/typeParameters.kt");
}
@Test
@TestMetadata("typeUsage.kt")
public void testTypeUsage() throws Exception {
runTest("compiler/testData/diagnostics/tests/multiplatform/annotationMatching/typeUsage.kt");
}
@Test
@TestMetadata("typeUsageWithImplicitType.kt")
public void testTypeUsageWithImplicitType() throws Exception {
runTest("compiler/testData/diagnostics/tests/multiplatform/annotationMatching/typeUsageWithImplicitType.kt");
}
@Test
@TestMetadata("typeUsageWithUnresolvedReference.kt")
public void testTypeUsageWithUnresolvedReference() throws Exception {
runTest("compiler/testData/diagnostics/tests/multiplatform/annotationMatching/typeUsageWithUnresolvedReference.kt");
}
@Test
@TestMetadata("typealias.kt")
public void testTypealias() throws Exception {
@@ -1,36 +1,35 @@
// -- Module: <m1-common> --
// -- Module: <m1-jvm> --
/jvm.kt:44:14: warning: annotation `@Ann` is missing on actual declaration.
/jvm.kt:47:14: warning: annotation `@Ann` is missing on actual declaration.
All annotations from expect `class OnClass defined in root package in file common.kt` must be present with the same arguments on actual `class OnClass defined in root package in file jvm.kt`, otherwise they might behave incorrectly.
actual class OnClass
^
/jvm.kt:47:16: warning: annotation `@Ann` is missing on actual declaration.
/jvm.kt:50:16: warning: annotation `@Ann` is missing on actual declaration.
All annotations from expect `fun onMember(): Unit defined in OnMember` must be present with the same arguments on actual `fun onMember(): Unit defined in OnMember`, otherwise they might behave incorrectly.
actual fun onMember() {}
^
/jvm.kt:52:18: warning: annotation `@Ann` is missing on actual declaration.
/jvm.kt:55:18: warning: annotation `@Ann` is missing on actual declaration.
All annotations from expect `class ViaTypealias defined in root package in file common.kt` must be present with the same arguments on actual `class ViaTypealiasImpl defined in root package in file jvm.kt`, otherwise they might behave incorrectly.
actual typealias ViaTypealias = ViaTypealiasImpl
^
/jvm.kt:57:18: warning: annotation `@Ann` is missing on actual declaration.
/jvm.kt:60:18: warning: annotation `@Ann` is missing on actual declaration.
All annotations from expect `fun foo(): Unit defined in MemberScopeViaTypealias` must be present with the same arguments on actual `fun foo(): Unit defined in MemberScopeViaTypealiasImpl`, otherwise they might behave incorrectly.
actual typealias MemberScopeViaTypealias = MemberScopeViaTypealiasImpl
^
/jvm.kt:60:12: warning: annotation `@WithArg(s = "str")` has different arguments on actual declaration: `@WithArg(s = "other str")`.
/jvm.kt:63:12: warning: annotation `@WithArg(s = "str")` has different arguments on actual declaration: `@WithArg(s = "other str")`.
All annotations from expect `fun withDifferentArg(): Unit defined in root package in file common.kt` must be present with the same arguments on actual `fun withDifferentArg(): Unit defined in root package in file jvm.kt`, otherwise they might behave incorrectly.
actual fun withDifferentArg() {}
^
/jvm.kt:62:12: warning: annotation `@Ann` is missing on actual declaration.
/jvm.kt:65:12: warning: annotation `@Ann` is missing on actual declaration.
All annotations from expect `fun inValueParam(arg: String): Unit defined in root package in file common.kt` must be present with the same arguments on actual `fun inValueParam(arg: String): Unit defined in root package in file jvm.kt`, otherwise they might behave incorrectly.
actual fun inValueParam(arg: String) {}
^
/jvm.kt:64:16: warning: annotation `@Ann` is missing on actual declaration.
/jvm.kt:67:16: warning: annotation `@Ann` is missing on actual declaration.
All annotations from expect `fun <T> inTypeParam(): Unit defined in root package in file common.kt` must be present with the same arguments on actual `fun <T> inTypeParam(): Unit defined in root package in file jvm.kt`, otherwise they might behave incorrectly.
actual fun <T> inTypeParam() {}
^
/jvm.kt:66:12: warning: annotation `@Ann` is missing on actual declaration.
/jvm.kt:69:12: warning: annotation `@Ann` is missing on actual declaration.
All annotations from expect `val onGetter: String defined in root package in file common.kt` must be present with the same arguments on actual `val onGetter: String defined in root package in file jvm.kt`, otherwise they might behave incorrectly.
actual val onGetter: String = ""
^
@@ -1,23 +1,23 @@
/jvm.kt:(103,110): warning: Annotation `@Ann()` is missing on actual declaration.
/jvm.kt:(106,113): warning: Annotation `@Ann()` is missing on actual declaration.
All annotations from expect 'class OnClass : Any' must be present with the same arguments on actual 'class OnClass : Any', otherwise they might behave incorrectly.
/jvm.kt:(151,159): warning: Annotation `@Ann()` is missing on actual declaration.
/jvm.kt:(154,162): warning: Annotation `@Ann()` is missing on actual declaration.
All annotations from expect 'fun onMember(): Unit' must be present with the same arguments on actual 'fun onMember(): Unit', otherwise they might behave incorrectly.
/jvm.kt:(209,221): warning: Annotation `@Ann()` is missing on actual declaration.
/jvm.kt:(212,224): warning: Annotation `@Ann()` is missing on actual declaration.
All annotations from expect 'class ViaTypealias : Any' must be present with the same arguments on actual 'class ViaTypealiasImpl : Any', otherwise they might behave incorrectly.
/jvm.kt:(314,337): warning: Annotation `@Ann()` is missing on actual declaration.
/jvm.kt:(317,340): warning: Annotation `@Ann()` is missing on actual declaration.
All annotations from expect 'fun foo(): Unit' must be present with the same arguments on actual 'fun foo(): Unit', otherwise they might behave incorrectly.
/jvm.kt:(402,418): warning: Annotation `@WithArg(s = String(str))` has different arguments on actual declaration: `@WithArg(s = String(other str))`.
/jvm.kt:(405,421): warning: Annotation `@WithArg(s = String(str))` has different arguments on actual declaration: `@WithArg(s = String(other str))`.
All annotations from expect 'fun withDifferentArg(): Unit' must be present with the same arguments on actual 'fun withDifferentArg(): Unit', otherwise they might behave incorrectly.
/jvm.kt:(436,448): warning: Annotation `@Ann()` is missing on actual declaration.
/jvm.kt:(439,451): warning: Annotation `@Ann()` is missing on actual declaration.
All annotations from expect 'fun inValueParam(arg: String): Unit' must be present with the same arguments on actual 'fun inValueParam(arg: String): Unit', otherwise they might behave incorrectly.
/jvm.kt:(481,492): warning: Annotation `@Ann()` is missing on actual declaration.
/jvm.kt:(484,495): warning: Annotation `@Ann()` is missing on actual declaration.
All annotations from expect 'fun <T> inTypeParam(): Unit' must be present with the same arguments on actual 'fun <T> inTypeParam(): Unit', otherwise they might behave incorrectly.
/jvm.kt:(510,518): warning: Annotation `@PROPERTY_GETTER:Ann()` is missing on actual declaration.
/jvm.kt:(513,521): warning: Annotation `@PROPERTY_GETTER:Ann()` is missing on actual declaration.
All annotations from expect 'val onGetter: String get(): String' must be present with the same arguments on actual 'val onGetter: String get(): String', otherwise they might behave incorrectly.
@@ -8,6 +8,7 @@
AnnotationTarget.TYPE_PARAMETER,
AnnotationTarget.PROPERTY_GETTER,
AnnotationTarget.PROPERTY_SETTER,
AnnotationTarget.TYPE,
)
annotation class Ann
@@ -39,6 +40,8 @@ expect fun <@Ann T> inTypeParam()
@get:Ann
expect val onGetter: String
expect fun onType(param: @Ann Any)
// MODULE: m1-jvm()()(m1-common)
// FILE: jvm.kt
<!ACTUAL_ANNOTATIONS_NOT_MATCH_EXPECT!>actual class <!ACTUAL_ANNOTATIONS_NOT_MATCH_EXPECT!>OnClass<!><!>
@@ -64,3 +67,5 @@ actual fun <!ACTUAL_ANNOTATIONS_NOT_MATCH_EXPECT!>withDifferentArg<!>() {}<!>
<!ACTUAL_ANNOTATIONS_NOT_MATCH_EXPECT!>actual fun <T> <!ACTUAL_ANNOTATIONS_NOT_MATCH_EXPECT!>inTypeParam<!>() {}<!>
<!ACTUAL_ANNOTATIONS_NOT_MATCH_EXPECT, ACTUAL_ANNOTATIONS_NOT_MATCH_EXPECT!>actual val <!ACTUAL_ANNOTATIONS_NOT_MATCH_EXPECT!>onGetter<!>: String = ""<!>
actual fun onType(param: Any) {}
@@ -8,6 +8,7 @@
AnnotationTarget.TYPE_PARAMETER,
AnnotationTarget.PROPERTY_GETTER,
AnnotationTarget.PROPERTY_SETTER,
AnnotationTarget.TYPE,
)
annotation class Ann
@@ -39,6 +40,8 @@ expect fun <@Ann T> inTypeParam()
@get:Ann
expect val onGetter: String
expect fun onType(param: @Ann Any)
// MODULE: m1-jvm()()(m1-common)
// FILE: jvm.kt
actual class <!ACTUAL_ANNOTATIONS_NOT_MATCH_EXPECT!>OnClass<!>
@@ -64,3 +67,5 @@ actual fun <!ACTUAL_ANNOTATIONS_NOT_MATCH_EXPECT!>inValueParam<!>(arg: String) {
actual fun <T> <!ACTUAL_ANNOTATIONS_NOT_MATCH_EXPECT!>inTypeParam<!>() {}
actual val <!ACTUAL_ANNOTATIONS_NOT_MATCH_EXPECT!>onGetter<!>: String = ""
actual fun onType(param: Any) {}
@@ -0,0 +1,106 @@
// WITH_STDLIB
// MODULE: m1-common
// FILE: common.kt
@Target(AnnotationTarget.TYPE)
annotation class Ann
expect fun valueParameterType(arg: @Ann String)
expect fun returnType(): @Ann String
expect fun <T : @Ann Any> methodTypeParamBound()
expect class OnClassTypeParamBound<T : @Ann Any>
expect fun <T> typeParamBoundInWhere() where T : @Ann Any
interface I1
interface I2
expect fun <T> severalBounds() where T : I1, T : @Ann I2
<!INCOMPATIBLE_MATCHING{JVM}!>expect fun <T> severalBoundsDifferentOrder() where T : I2, T : @Ann I1<!>
<!INCOMPATIBLE_MATCHING{JVM}!>expect fun <T> lessTypeParamBoundsOnActual() where T : I1, T : @Ann I2<!>
expect fun @Ann Any.onReceiver()
expect class OnClassSuper : @Ann I1
expect class OnClassSuperDifferentOrder : I1, @Ann I2
expect class OnClassSuperMoreOnActual : @Ann I2
interface I3<T>
expect class OnClassSuperTypeParams<T> : I3<@Ann T>
expect fun deepInParamsTypes(arg: I3<I3<@Ann Any>>)
interface I4<T, U>
expect fun starProjection(arg: I4<*, @Ann Any>)
expect fun <T> typeArgWithVariance(t: I3<out @Ann T>)
class WithNested<T> {
inner class Nested<U>
}
expect fun qualifierPartsMatching(arg: WithNested<String>.Nested<@Ann String>)
expect fun qualifierPartsNonMatching(arg: WithNested<String>.Nested<@Ann String>)
<!INCOMPATIBLE_MATCHING{JVM}!>expect fun funTypeVsUserType(arg: () -> @Ann String)<!>
expect fun funcTypeReturnType(arg: () -> @Ann Any)
expect fun funcTypeReceiverType(arg: @Ann Any.() -> Unit)
expect fun funcTypeArgType(arg: (arg: @Ann Any) -> Unit)
// MODULE: m1-jvm()()(m1-common)
// FILE: jvm.kt
actual fun valueParameterType(arg: String) {}
actual fun returnType(): String = ""
actual fun <T : Any> methodTypeParamBound() {}
actual class OnClassTypeParamBound<T : Any>
actual fun <T> typeParamBoundInWhere() where T : Any {}
actual fun <T> severalBounds() where T : I1, T : I2 {}
actual fun <T> <!ACTUAL_WITHOUT_EXPECT!>severalBoundsDifferentOrder<!>() where T : @Ann I1, T : I2 {}
actual fun <T> <!ACTUAL_WITHOUT_EXPECT!>lessTypeParamBoundsOnActual<!>() where T : @Ann I2 {}
actual fun Any.onReceiver() {}
actual class OnClassSuper : I1
actual class OnClassSuperDifferentOrder : @Ann I2, I1
actual class OnClassSuperMoreOnActual : I1, I2
actual class OnClassSuperTypeParams<T> : I3<T>
actual fun deepInParamsTypes(arg: I3<I3<Any>>) {}
actual fun starProjection(arg: I4<*, Any>) {}
actual fun <T> typeArgWithVariance(t: I3<out T>) {}
actual fun qualifierPartsMatching(arg: WithNested<String>.Nested<@Ann String>) {}
actual fun qualifierPartsNonMatching(arg: WithNested<@Ann String>.Nested<String>) {}
actual fun <!ACTUAL_WITHOUT_EXPECT!>funTypeVsUserType<!>(arg: kotlin.jvm.functions.Function0<String>) {}
actual fun funcTypeReturnType(arg: () -> Any) {}
actual fun funcTypeReceiverType(arg: Any.() -> Unit) {}
actual fun funcTypeArgType(arg: (arg: Any) -> Unit) {}
@@ -0,0 +1,106 @@
// WITH_STDLIB
// MODULE: m1-common
// FILE: common.kt
@Target(AnnotationTarget.TYPE)
annotation class Ann
expect fun valueParameterType(arg: @Ann String)
expect fun returnType(): @Ann String
expect fun <T : @Ann Any> methodTypeParamBound()
expect class OnClassTypeParamBound<T : @Ann Any>
expect fun <T> typeParamBoundInWhere() where T : @Ann Any
interface I1
interface I2
expect fun <T> severalBounds() where T : I1, T : @Ann I2
expect fun <!NO_ACTUAL_FOR_EXPECT{JVM}!><T><!> severalBoundsDifferentOrder() where T : I2, T : @Ann I1
expect fun <!NO_ACTUAL_FOR_EXPECT{JVM}!><T><!> lessTypeParamBoundsOnActual() where T : I1, T : @Ann I2
expect fun @Ann Any.onReceiver()
expect class OnClassSuper : @Ann I1
expect class OnClassSuperDifferentOrder : I1, @Ann I2
expect class OnClassSuperMoreOnActual : @Ann I2
interface I3<T>
expect class OnClassSuperTypeParams<T> : I3<@Ann T>
expect fun deepInParamsTypes(arg: I3<I3<@Ann Any>>)
interface I4<T, U>
expect fun starProjection(arg: I4<*, @Ann Any>)
expect fun <T> typeArgWithVariance(t: I3<out @Ann T>)
class WithNested<T> {
inner class Nested<U>
}
expect fun qualifierPartsMatching(arg: WithNested<String>.Nested<@Ann String>)
expect fun qualifierPartsNonMatching(arg: WithNested<String>.Nested<@Ann String>)
expect fun funTypeVsUserType<!NO_ACTUAL_FOR_EXPECT{JVM}!>(arg: () -> @Ann String)<!>
expect fun funcTypeReturnType(arg: () -> @Ann Any)
expect fun funcTypeReceiverType(arg: @Ann Any.() -> Unit)
expect fun funcTypeArgType(arg: (arg: @Ann Any) -> Unit)
// MODULE: m1-jvm()()(m1-common)
// FILE: jvm.kt
actual fun valueParameterType(arg: String) {}
actual fun returnType(): String = ""
actual fun <T : Any> methodTypeParamBound() {}
actual class OnClassTypeParamBound<T : Any>
actual fun <T> typeParamBoundInWhere() where T : Any {}
actual fun <T> severalBounds() where T : I1, T : I2 {}
actual fun <!ACTUAL_WITHOUT_EXPECT!><T><!> severalBoundsDifferentOrder() where T : @Ann I1, T : I2 {}
actual fun <!ACTUAL_WITHOUT_EXPECT!><T><!> lessTypeParamBoundsOnActual() where T : @Ann I2 {}
actual fun Any.onReceiver() {}
actual class OnClassSuper : I1
actual class OnClassSuperDifferentOrder : @Ann I2, I1
actual class OnClassSuperMoreOnActual : I1, I2
actual class OnClassSuperTypeParams<T> : I3<T>
actual fun deepInParamsTypes(arg: I3<I3<Any>>) {}
actual fun starProjection(arg: I4<*, Any>) {}
actual fun <T> typeArgWithVariance(t: I3<out T>) {}
actual fun qualifierPartsMatching(arg: WithNested<String>.Nested<@Ann String>) {}
actual fun qualifierPartsNonMatching(arg: WithNested<@Ann String>.Nested<String>) {}
actual fun funTypeVsUserType<!ACTUAL_WITHOUT_EXPECT!>(arg: <!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>kotlin.jvm.functions.Function0<String><!>)<!> {}
actual fun funcTypeReturnType(arg: () -> Any) {}
actual fun funcTypeReceiverType(arg: Any.() -> Unit) {}
actual fun funcTypeArgType(arg: (arg: Any) -> Unit) {}
@@ -0,0 +1,11 @@
// FIR_IDENTICAL
// MODULE: m1-common
// FILE: common.kt
@Target(AnnotationTarget.TYPE)
annotation class Ann
expect fun foo(): @Ann Int
// MODULE: m1-jvm()()(m1-common)
// FILE: jvm.kt
actual fun foo() = 1
@@ -0,0 +1,10 @@
// MODULE: m1-common
// FILE: common.kt
@Target(AnnotationTarget.TYPE)
annotation class Ann
<!INCOMPATIBLE_MATCHING{JVM}!>expect fun <T : @Ann Any> foo()<!>
// MODULE: m1-jvm()()(m1-common)
// FILE: jvm.kt
actual fun <T : <!UNRESOLVED_REFERENCE!>Unresolved<!>> foo() {}
@@ -0,0 +1,10 @@
// MODULE: m1-common
// FILE: common.kt
@Target(AnnotationTarget.TYPE)
annotation class Ann
expect fun <!NO_ACTUAL_FOR_EXPECT{JVM}!><T : @Ann Any><!> foo()
// MODULE: m1-jvm()()(m1-common)
// FILE: jvm.kt
actual fun <!ACTUAL_WITHOUT_EXPECT!><T : <!UNRESOLVED_REFERENCE!>Unresolved<!>><!> foo() {}
@@ -24101,6 +24101,24 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
runTest("compiler/testData/diagnostics/tests/multiplatform/annotationMatching/typeParameters.kt");
}
@Test
@TestMetadata("typeUsage.kt")
public void testTypeUsage() throws Exception {
runTest("compiler/testData/diagnostics/tests/multiplatform/annotationMatching/typeUsage.kt");
}
@Test
@TestMetadata("typeUsageWithImplicitType.kt")
public void testTypeUsageWithImplicitType() throws Exception {
runTest("compiler/testData/diagnostics/tests/multiplatform/annotationMatching/typeUsageWithImplicitType.kt");
}
@Test
@TestMetadata("typeUsageWithUnresolvedReference.kt")
public void testTypeUsageWithUnresolvedReference() throws Exception {
runTest("compiler/testData/diagnostics/tests/multiplatform/annotationMatching/typeUsageWithUnresolvedReference.kt");
}
@Test
@TestMetadata("typealias.kt")
public void testTypealias() throws Exception {