[FE, IR] Check annotations compatibility on expect and actual type parameters
^KT-60671
This commit is contained in:
committed by
Space Team
parent
420dceb7d8
commit
8fb2935ef6
+26
@@ -112,6 +112,7 @@ object AbstractExpectActualAnnotationMatchChecker {
|
||||
actualSymbol: DeclarationSymbolMarker,
|
||||
): Incompatibility? {
|
||||
areAnnotationsSetOnDeclarationsCompatible(expectSymbol, actualSymbol)?.let { return it }
|
||||
areAnnotationsOnTypeParametersCompatible(expectSymbol, actualSymbol)?.let { return it }
|
||||
|
||||
return null
|
||||
}
|
||||
@@ -134,6 +135,31 @@ object AbstractExpectActualAnnotationMatchChecker {
|
||||
}
|
||||
}
|
||||
|
||||
context (ExpectActualMatchingContext<*>)
|
||||
private fun areAnnotationsOnTypeParametersCompatible(
|
||||
expectSymbol: DeclarationSymbolMarker,
|
||||
actualSymbol: DeclarationSymbolMarker,
|
||||
): Incompatibility? {
|
||||
fun DeclarationSymbolMarker.getTypeParameters(): List<TypeParameterSymbolMarker>? {
|
||||
return when (this) {
|
||||
is FunctionSymbolMarker -> typeParameters
|
||||
is RegularClassSymbolMarker -> typeParameters
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
val expectParams = expectSymbol.getTypeParameters() ?: return null
|
||||
val actualParams = actualSymbol.getTypeParameters() ?: return null
|
||||
if (expectParams.size != actualParams.size) return null
|
||||
|
||||
return expectParams.zip(actualParams).firstNotNullOfOrNull { (expectParam, actualParam) ->
|
||||
areAnnotationsSetOnDeclarationsCompatible(expectParam, actualParam)?.let {
|
||||
// Write containing declarations into diagnostic
|
||||
Incompatibility(expectSymbol, actualSymbol, actualParam.getSourceElement(), it.type)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
context (ExpectActualMatchingContext<*>)
|
||||
private fun areAnnotationsSetOnDeclarationsCompatible(
|
||||
expectSymbol: DeclarationSymbolMarker,
|
||||
|
||||
Reference in New Issue
Block a user