Repository navigation
fix(kotlin): link a typed-receiver call to an extension declared in a package - #481
Merged
Merged
Conversation
…n declared in a package
An extension function is stored as `Foo::shout` whatever its package, while
the class it extends is `pkg::Foo`. The typed-receiver lookup found a method
by the class's qualified name, so the extension linked only in files with no
`package` line (the common project has one, so it got no edge). When the
receiver's class has no such member, a Kotlin call now falls back to the one
visible extension of that name whose receiver accepts the type, as an
implicit receiver already does.
On JetBrains Exposed (2155404) 1,020 call links are gained and none is lost;
a sample of 16 and the ones whose owner is a standard type
(Sequence, Set, Triple, Iterable, String) all check out against the source.
The golden dumps do not move. kotlin-infix-calls pinned the gap ('an
extension on a project class is not linked through a typed receiver'); it now
expects `Int::and`.
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.
In Kotlin, a call on a typed receiver now links to an extension function declared in a package, such as
value.shout()or the infixa join b.On JetBrains Exposed (2155404) this adds 1,020 call links and removes none; node sets are identical. A sample of 16 of the new links, and the ones whose owner is a standard type (Sequence, Set, Triple, Iterable, String), were checked against the source and all point at the right extension.
Cause
An extension function is stored as
Foo::shout(receiver as written, no package) while the class it extends ispkg::Foo. The typed-receiver lookup found members by{class qualified name}::{name}, so an extension in a packaged file was never found. The same extension did link when the file had nopackageline, or through an implicit receiver.Change
kotlin_receiver.rs: the existing candidate scan for extensions is nowkotlin_extension_member, called at the end ofkotlin_receiver_memberas before.method_call.rs: when the inferable-receiver path finds no member on the receiver's class and the language is Kotlin, it falls back tokotlin_extension_member. A real member still wins.__tests__/kotlin-extension-call-typed-receiver.test.ts: constructor-typed and parameter-typed receivers, an infix call, member-wins, a different receiver type, and an unrelated extension.__tests__/kotlin-infix-calls.test.ts: the "project numeric extension" case pinned the gap ([]); it now expectsInt::and, the extension on a project class declared in a package.Checks
Summary by cubic
Links Kotlin calls on typed receivers to extension functions declared in a package, such as
value.shout()or the infixa join bwhereshout/joinextend a class underpackage demo. Previously such calls linked only when the extension's file had nopackageline, so typical Kotlin projects got no edge.Int::and.Written for commit da70ad6. Summary will update on new commits.
Summary by CodeRabbit