[FE] Relax rules of matching @Target annotation on expect and actual
Allow `expect` targets to be subset of `actual`. ^KT-58551
This commit is contained in:
committed by
Space Team
parent
ad84c83ee9
commit
6611a55a60
+11
-3
@@ -14,6 +14,7 @@ import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.calls.components.ClassicTypeSystemContextForCS
|
||||
import org.jetbrains.kotlin.resolve.calls.mpp.ExpectActualCollectionArgumentsCompatibilityCheckStrategy
|
||||
import org.jetbrains.kotlin.resolve.calls.mpp.ExpectActualMatchingContext
|
||||
import org.jetbrains.kotlin.resolve.calls.mpp.ExpectActualMatchingContext.AnnotationCallInfo
|
||||
import org.jetbrains.kotlin.resolve.checkers.OptInNames
|
||||
@@ -337,11 +338,18 @@ class ClassicExpectActualMatchingContext(val platformModule: ModuleDescriptor) :
|
||||
override val DeclarationSymbolMarker.annotations: List<AnnotationCallInfo>
|
||||
get() = asDescriptor().annotations.map(::AnnotationCallInfoImpl)
|
||||
|
||||
|
||||
override fun areAnnotationArgumentsEqual(annotation1: AnnotationCallInfo, annotation2: AnnotationCallInfo): Boolean {
|
||||
override fun areAnnotationArgumentsEqual(
|
||||
annotation1: AnnotationCallInfo,
|
||||
annotation2: AnnotationCallInfo,
|
||||
collectionArgumentsCompatibilityCheckStrategy: ExpectActualCollectionArgumentsCompatibilityCheckStrategy,
|
||||
): Boolean {
|
||||
fun AnnotationCallInfo.getDescriptor(): AnnotationDescriptor = (this as AnnotationCallInfoImpl).annotationDescriptor
|
||||
|
||||
return areExpressionConstValuesEqual(annotation1.getDescriptor(), annotation2.getDescriptor())
|
||||
return areExpressionConstValuesEqual(
|
||||
annotation1.getDescriptor(),
|
||||
annotation2.getDescriptor(),
|
||||
collectionArgumentsCompatibilityCheckStrategy,
|
||||
)
|
||||
}
|
||||
|
||||
private class AnnotationCallInfoImpl(
|
||||
|
||||
+14
-5
@@ -6,10 +6,15 @@
|
||||
package org.jetbrains.kotlin.resolve.multiplatform
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
|
||||
import org.jetbrains.kotlin.resolve.calls.mpp.ExpectActualCollectionArgumentsCompatibilityCheckStrategy
|
||||
import org.jetbrains.kotlin.resolve.calls.mpp.ExpectActualMatchingContext
|
||||
import org.jetbrains.kotlin.resolve.constants.ConstantValue
|
||||
|
||||
internal fun ExpectActualMatchingContext<*>.areExpressionConstValuesEqual(a: Any?, b: Any?): Boolean {
|
||||
internal fun ExpectActualMatchingContext<*>.areExpressionConstValuesEqual(
|
||||
a: Any?,
|
||||
b: Any?,
|
||||
collectionArgumentsCompatibilityCheckStrategy: ExpectActualCollectionArgumentsCompatibilityCheckStrategy,
|
||||
): Boolean {
|
||||
return when {
|
||||
a is AnnotationDescriptor && b is AnnotationDescriptor -> {
|
||||
val aArgs = a.allValueArguments
|
||||
@@ -17,16 +22,20 @@ internal fun ExpectActualMatchingContext<*>.areExpressionConstValuesEqual(a: Any
|
||||
a.fqName == b.fqName &&
|
||||
aArgs.size == bArgs.size &&
|
||||
areCompatibleExpectActualTypes(a.type, b.type) &&
|
||||
aArgs.keys.all { k -> areExpressionConstValuesEqual(aArgs[k], bArgs[k]) }
|
||||
aArgs.keys.all { k -> areExpressionConstValuesEqual(aArgs[k], bArgs[k], collectionArgumentsCompatibilityCheckStrategy) }
|
||||
}
|
||||
a is ConstantValue<*> && b is ConstantValue<*> -> {
|
||||
areExpressionConstValuesEqual(a.value, b.value)
|
||||
areExpressionConstValuesEqual(a.value, b.value, collectionArgumentsCompatibilityCheckStrategy)
|
||||
}
|
||||
a is Collection<*> && b is Collection<*> -> {
|
||||
a.size == b.size && a.zip(b).all { (f, s) -> areExpressionConstValuesEqual(f, s) }
|
||||
collectionArgumentsCompatibilityCheckStrategy.areCompatible(a, b) { f, s ->
|
||||
areExpressionConstValuesEqual(f, s, collectionArgumentsCompatibilityCheckStrategy)
|
||||
}
|
||||
}
|
||||
a is Array<*> && b is Array<*> -> {
|
||||
a.size == b.size && a.zip(b).all { (f, s) -> areExpressionConstValuesEqual(f, s) }
|
||||
collectionArgumentsCompatibilityCheckStrategy.areCompatible(a.toList(), b.toList()) { f, s ->
|
||||
areExpressionConstValuesEqual(f, s, collectionArgumentsCompatibilityCheckStrategy)
|
||||
}
|
||||
}
|
||||
else -> a == b
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user