K1: Report deprecation on synthetic properties for NOT_CONSIDERED JDK members

Currently, for other synthetic properties, deprecation from the original
method is already being propagated to the relevant new synthetic
property accessor.

But what we need is also reporting warnings on synthetic properties
accessors call-sites if original methods are considered deprecated
as a result of deprecation propagation.

KT-60659 Fixed
^KT-60769 Fixed
This commit is contained in:
Denis.Zharkov
2023-07-28 19:56:10 +02:00
committed by Space Team
parent eae97e4f76
commit 0694ee50a3
11 changed files with 252 additions and 27 deletions
@@ -39,27 +39,50 @@ class DeprecationResolver(
) {
private val deprecations: MemoizedFunctionToNotNull<DeclarationDescriptor, DeprecationInfo> =
storageManager.createMemoizedFunction { descriptor ->
val deprecations = descriptor.getOwnDeprecations()
when {
deprecations.isNotEmpty() -> DeprecationInfo(deprecations, hasInheritedDeprecations = false)
descriptor is CallableMemberDescriptor -> {
val inheritedDeprecations = listOfNotNull(deprecationByOverridden(descriptor))
when (inheritedDeprecations.isNotEmpty()) {
true -> when (languageVersionSettings.supportsFeature(LanguageFeature.StopPropagatingDeprecationThroughOverrides)) {
true -> DeprecationInfo(
inheritedDeprecations.filter { it.forcePropagationToOverrides },
hasInheritedDeprecations = true,
inheritedDeprecations
)
false -> DeprecationInfo(inheritedDeprecations, hasInheritedDeprecations = true)
}
false -> DeprecationInfo.EMPTY
}
}
else -> DeprecationInfo.EMPTY
}
computeDeprecation(descriptor)
}
private fun computeDeprecation(descriptor: DeclarationDescriptor): DeprecationInfo {
val deprecations = descriptor.getOwnDeprecations()
return when {
deprecations.isNotEmpty() -> DeprecationInfo(deprecations, hasInheritedDeprecations = false)
descriptor is PropertyAccessorDescriptor && descriptor.correspondingProperty is SyntheticPropertyDescriptor -> {
val syntheticProperty = descriptor.correspondingProperty as SyntheticPropertyDescriptor
val originalMethod =
if (descriptor is PropertyGetterDescriptor) syntheticProperty.getMethod else syntheticProperty.setMethod
@Suppress("FoldInitializerAndIfToElvis") // Wait until KTIJ-26450 is fixed
if (originalMethod == null) return DeprecationInfo.EMPTY
val originalMethodDeprecationInfo = deprecations(originalMethod)
// Limiting these new (they didn't exist before 1.9.10) deprecations only to WARNING and forcePropagationToOverrides
// (i.e., for overrides of NOT_CONSIDERED JDK members)
// is deliberate once we would like to reduce the scope of affected usages because otherwise
// it might be a big unexpected breaking change for users who are enabled -Werror flag.
val filteredDeprecations =
originalMethodDeprecationInfo.deprecations.filter {
it.deprecationLevel == DeprecationLevelValue.WARNING && it.forcePropagationToOverrides
}
return originalMethodDeprecationInfo.copy(deprecations = filteredDeprecations)
}
descriptor is CallableMemberDescriptor -> {
val inheritedDeprecations = listOfNotNull(deprecationByOverridden(descriptor))
when (inheritedDeprecations.isNotEmpty()) {
true -> when (languageVersionSettings.supportsFeature(LanguageFeature.StopPropagatingDeprecationThroughOverrides)) {
true -> DeprecationInfo(
inheritedDeprecations.filter { it.forcePropagationToOverrides },
hasInheritedDeprecations = true,
inheritedDeprecations
)
false -> DeprecationInfo(inheritedDeprecations, hasInheritedDeprecations = true)
}
false -> DeprecationInfo.EMPTY
}
}
else -> DeprecationInfo.EMPTY
}
}
private data class DeprecationInfo(
val deprecations: List<DescriptorBasedDeprecationInfo>,
val hasInheritedDeprecations: Boolean,