Skip to content

Commit 21539f8

Browse files
committed
Fix: an expect Kotlin function having Kotlin atomics in its signature cannot be actualized with a function using Java atomics.
1 parent e1288fd commit 21539f8

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

proposals/common-atomics.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,15 +232,21 @@ Though this is not a breaking change (the old Kotlin code using Java atomics wil
232232
**How we can address this Kotlin-Java-Kotlin hierarchy problem:**
233233

234234
- From the front-end point of view, there can be a subtyping relation between `AtomicInt` and `AtomicInteger`,
235-
then we can load java classes doing the full mapping like in the option 1, but mapping java `AtomicInteger` types to flexible types `AtomicInt`..`AtomicInteger`.
235+
then we can load java classes doing the full mapping like in the option 1, but mapping java `AtomicInteger` types to _flexible types_ `AtomicInt`..`AtomicInteger`.
236236
- Forbid to use Kotlin atomics in open functions (via `@OptIn` or a compiler flag).
237237
- We could introduce a compiler check: some Java function overrides a Kotlin function with Kotlin atomics in the signature.
238238

239-
**Can we actualize an expect function with `kotlin.AtomicInt` with an actual function with `j.u.c.a.AtomicInteger`?**
239+
**Can we actualize an expect function with `k.c.a.AtomicInt` with an actual function with `j.u.c.a.AtomicInteger`?**
240+
241+
With the implementation, when Kotlin and Java atomics are incompatible types until codegen,
242+
one cannot actualize an expect function having a `k.c.a.AtomicInt` in its signature with the function using `j.u.c.a.AtomicInteger`.
243+
240244
- When the actual function is written in Kotlin
241-
- In this case the user should migrate to `kotlin.AtomicInt` in kotlin code first.
245+
- the user should migrate to `k.c.a.AtomicInt` in kotlin code first.
242246
- When the actual function is written in Java
243-
- with the help of `@KotlinActual` annotation.
247+
- Unfortunately, an expect Kotlin function using Kotlin atomics cannot be actualized with a Java implementation using `@KotlinActual` annotation.
248+
Though if this scenario appears to be popular, it may be supported in the compiler by introduction of _flexible type mapping_ at FIR,
249+
which was mentioned as one of the possible solutions to the Kotlin-Java-Kotlin hierarchy problem above.
244250

245251
**Java Interop:**
246252

0 commit comments

Comments
 (0)