Repository navigation
fix(kotlin): a Multiplatform import reaches what the caller compiles against - #3191
Merged
Merged
Conversation
…against A Kotlin Multiplatform `expect` and its `actual`s share one qualified name, and a reference through an import took the nearest declaration, the `expect` on a tie. That suits common code only. PR #3023 sent Java's calls through this pick, so `Util.go()` from `app/src/main/java`, which 1.6.2 linked to the `androidMain` `actual` by a name guess, reached the `commonMain` `expect`, and so did `extends Timber.Tree`, which 1.6.2 left unresolved. An `expect` isn't in JVM bytecode, so a Java caller can never reach one. Kotlin in `androidUnitTest` or a plain Android module went the same way. The fix: pickJvmDeclaration chooses by what the caller compiles against, for the owner of an imported reference and for the import itself. Common source sets (`commonMain`, `commonTest`, okhttp's `commonJvmAndroid`) keep the nearest declaration. A platform's source sets take that platform's `actual`, so `androidUnitTest` takes `androidMain`'s, or that of a target they build on (`iosArm64Main` from `iosMain`), and otherwise the `expect`, as an intermediate set like `nativeMain` sees. Java and a plain Kotlin module take a JVM target's `actual`, never `iosMain`'s: the one their path names, else not Android's, so okhttp's samples reach `jvmMain` and its `android-test` `androidMain`. This reimplements the idea of PR #3136 by @johnhldiver-beep, who found the cause. Beyond it: `commonTest` stays on the `expect` (that PR's check named `commonMain` alone), `androidUnitTest` finds `androidMain`, Java never lands on a native target's `actual`, and the import edge agrees with the calls. Validation: - kotlin-expect-actual-callers.test.ts, 10 cases built from the issue's repro and timber's and okhttp's shapes: 8 fail on main, all pass. - 1.6.2 run first: the Java cases link the `actual` by a 0.65 guess, so this is a regression from #3023, as the issue says. - A/B against main 4499d00: okhttp 9 imports and references move from the `expect` in `commonJvmAndroid` to the platform `actual`, each to the target its module builds for; nowinandroid, mihon and every Java repo unchanged, having no `expect`. Controls flask and express identical. - CPU, mihon, median of 3 interleaved: 20.02 to 19.86 s. Resolution only. Fixes #3033 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Reimplements #3136 by @johnhldiver-beep.
A Kotlin Multiplatform
expectand itsactuals share one qualified name,and a reference through an import took the nearest declaration, the
expecton a tie. That suits common code only. PR #3023 sent Java's calls through this
pick, so
Util.go()fromapp/src/main/java, which 1.6.2 linked to theandroidMainactualby a name guess, reached thecommonMainexpect, andso did
extends Timber.Tree, which 1.6.2 left unresolved. Anexpectisn't inJVM bytecode, so a Java caller can never reach one. Kotlin in
androidUnitTestor a plain Android module went the same way.
The fix: pickJvmDeclaration chooses by what the caller compiles against, for
the owner of an imported reference and for the import itself. Common source
sets (
commonMain,commonTest, okhttp'scommonJvmAndroid) keep the nearestdeclaration. A platform's source sets take that platform's
actual, soandroidUnitTesttakesandroidMain's, or that of a target they build on(
iosArm64MainfromiosMain), and otherwise theexpect, as an intermediateset like
nativeMainsees. Java and a plain Kotlin module take a JVM target'sactual, neveriosMain's: the one their path names, else not Android's, sookhttp's samples reach
jvmMainand itsandroid-testandroidMain.This reimplements the idea of PR #3136 by @johnhldiver-beep, who found the
cause. Beyond it:
commonTeststays on theexpect(that PR's check namedcommonMainalone),androidUnitTestfindsandroidMain, Java never lands ona native target's
actual, and the import edge agrees with the calls.Validation:
and timber's and okhttp's shapes: 8 fail on main, all pass.
actualby a 0.65 guess, so this isa regression from fix(jvm): a call through an import reaches the Java or Kotlin class it names #3023, as the issue says.
expectincommonJvmAndroidto the platformactual, each to the targetits module builds for; nowinandroid, mihon and every Java repo unchanged,
having no
expect. Controls flask and express identical.Fixes #3033
Suite: 874 files passed, 6 skipped; 10,847 tests passed, 2 expected fail, 87 skipped, with the kernel on Windows, on the stack of these 8 PRs at 00b79ff2 over main 1f188da. The A/B numbers are against 4499d00; the stack on 1f188da is edge for edge the same arm on jsoup, rocksdb's java/, Minestom, okhttp, tokio, caddy, Alamofire, nowinandroid and mihon, and those repos give the same graph on both mains.
🤖 Generated with Claude Code