MP-3345: Consider ignoring invocations and overriding of deprecated Kotlin default methods - #1560
Open
Rafał Wokacz (rawo) wants to merge 1 commit into
Conversation
…otlin default methods
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When a Kotlin interface method is marked Daniel Edeling (@deprecated), the
pre--Xjvm-defaultcompilation strategy generates anInterface$DefaultImplsholder class for the method body, plus a compiler-generated stub in every implementing class that forwards to it. Plugin Verifier reported this compiler artifact as two false-positive warnings the plugin author never actually wrote:KotlinInterface.DefaultImpls.foo(this)is deprecated but called fromPluginClassPluginClass.foooverrides deprecated funfoo()This same class of false positive was already fixed once before for @ApiStatus.Internal/@IntellijInternalApi usages (
InternalApiUsage.kt,InternalMethodOverridingProcessor.kt), but the equivalent fix was never applied to deprecation checks.Fix
KotlinDefaultImplsUsageFilter, a newApiUsageFilterthat ignores invocations of methods owned by a synthetic$DefaultImplsclass, and composed it intoDeprecatedApiUsageProcessoralongside the existingSamePluginUsageFilter.CompositeApiUsageFilterto forward all three allow() overloads (class-reference, method-invocation, field-access) to its child filters — it previously only forwarded the method-invocation one, which would have silently broken SamePluginUsageFilter's existing class-reference/field-access suppression once wrapped in a composite.KotlinMethods.isKotlinDefaultMethod()bytecode-pattern detector, skipping the compiler-generated stub override.isKotlinDefaultMethod()only recognizes the pre--Xjvm-default $DefaultImpls-forwarding shape, not Kotlin 2.2+'s alternate stub shape.Testing
DeprecatedDefaultMethodInterface,NoOverrideOfDeprecatedDefaultMethod,ExplicitOverrideOfDeprecatedDefaultMethod,SamePluginDeprecatedOverride) exercising:isKotlinDefaultMethod()guard, unlike hasDifferentOrigin, doesn't regress same-origin detection).DeprecatedKotlinDefaultMethodTest, pinningKotlinDefaultImplsUsageFilterand theisKotlinDefaultMethod()-based override guard against hand-built ASM bytecode, independent of the current Kotlin toolchain version.