https://kotlinlang.org logo
#compiler
Title
# compiler
j

jessewilson

03/04/2024, 4:26 PM
I forgot to import
kotlinx.datetime.Instant
in a unit test and my code compiled just fine. What’s happening? Here’s the file that incorrectly compiles, and a screenshot showing that IntelliJ doesn’t mind that I forgot the import.
o

Oleg Yukhnevich

03/04/2024, 4:39 PM
it's expected 1. because you have
Instant
in
okio
package in test module link 2. And it's actualized by
kotlinx.datetime.Instant
here (for all targets except Wasm) So in your
zlib
sourceSet you have imported by default
okio.Instant
, and because
zlib
sourceSet is a common for jvm+native, and so it's actualized via a typealias to
kotlinx.datetime.Instant
, you have just
Instant=kotlinx.datetime.Instant
no magic in the end 🙃
j

jessewilson

03/04/2024, 4:52 PM
Phew
Operator error!
Thanks Oleg!
🙃 1
o

Oleg Yukhnevich

03/04/2024, 4:56 PM
but it was not as easy as I would thought - for some reason when clicking on
Instant
here in IDEA it will redirect directly to
kotlinx.datetime.Instant
instead of typealias in a project Still, IDEA shows a lot of useful information during typing 🙂
2 Views