I'm getting an IDE error but, oddly, my code compi...
# getting-started
c
I'm getting an IDE error but, oddly, my code compiles and runs just fine. As a Linux application, anyway.
h
The IO dispatcher is JVM only. Use default or create a custom dispatcher on Linux.
c
Okay, but why does it compile?
s
@hfhbd I think he's already building for JVM (on Linux). Compose/Desktop doesn't support native desktop targets yet; there's some experimental work on native support (only for macOS at the moment) but nothing production-ready.
@Chris B This seems to be an IDE issue, maybe try clearing caches/restart.
c
I've already cleared the caches and restarted, multiple times. It cleared up some problems I had (I had included the extended icons but the IDE refused to recognize or import them until I deleted the
.gradle
and
.idea
directories) but didn't affect this one.
s
I see, that's quite odd actually 😅 Have you tried on another, clean-slate project? Also, if you're by any chance using the experimental K2 mode for the Kotlin plugin, it could be from that, in that case report the issue to JetBrains.
c
I'm not on the experimental mode, AFAIK. I haven't tried a clean-slate project.
This one was generated by https://kmp.jetbrains.com/, if that would do it.
s
Ah, I see. Which platforms (targets) does the project support aside from JVM? And where is this piece of code located, which source set (e.g. commonMain or jvmMain...)?
c
It's in commonMain. targeting Android, Desktop, and Web.
s
Ah, I see the issue now.
The wasmJS and JS targets don't have
<http://Dispatchers.IO|Dispatchers.IO>
Since you're only allowed to use the stuff that's shared between all platforms on
commonMain
, the IDE rightfully shows an error, because if you try building the wasmJs/js targets, the compiler will error out as well.
c
I didn't realize the IDE would flag errors that way. It's very confusing.
s
As you're building for JVM, the API is available (to the compiler) so the build succeeds. IMHO this is quite weird, I think the Kotlin Multiplatform plugin should cause a build error (or at least a warning), to alert you that you're using platform-specific code in
commonMain
.
This way it'll force you to do the correct thing and move that code to platform-specific folders.
I think the other way around, the IDE's behavior is correct and expected, but the compiler's behavior is kinda confusing, it should warn you about it.
@Igor Demin What do you think about this? (sorry if you're unrelated to the compiler/multiplatform team, I just picked someone from Jetbrains 😅 )
d
We are working on new compilation scheme which will pickup only common dependencies during compilation of the common souresets during platform compilation, but it is really complex task and there is much to do
👍 2