Imports in kotlin repl not working?

Having some strange behavior with imports in kotlinc-jvm – only the first import seems to work. For example:

~ kotlinc-jvm
Welcome to Kotlin version 1.0.0 (JRE 1.8.0_71-b15)
Type :help for help, :quit for quit
>>> import java.util.Base64
>>> var e = Base64.getEncoder()
>>> import java.nio.ByteBuffer
>>> var bb = ByteBuffer.wrap(ByteArray(16))
error: unresolved reference: ByteBuffer
var bb = ByteBuffer.wrap(ByteArray(16))
         ^

but if running the above two imports in reverse order:

~ kotlinc-jvm
Welcome to Kotlin version 1.0.0 (JRE 1.8.0_71-b15)
Type :help for help, :quit for quit
>>> import java.nio.ByteBuffer
>>> var bb = ByteBuffer.wrap(ByteArray(16))
>>> import java.util.Base64
>>> var e = Base64.getEncoder()
error: unresolved reference: Base64
var e = Base64.getEncoder()
        ^

I note that it does work correctly when running a script using the -script parameter (but the script has to be named correctly with a .kts extension otherwise there are other errors).

2 Likes

Same with me, just the first import is actually performed, all subsequent ones are ignored when using the repl in a terminal window. Is there a ticket for this issue already? Or any workaround?

There’s no ticket for this issue, please report one at https://youtrack.jetbrains.com/issues/KT. Thanks!

Done, see and vote for https://youtrack.jetbrains.com/issue/KT-11428

1 Like

Hello, guys. Perhaps, I was doing something wrong, but when I tryed to execute code in REPL with imports from my project, it showed me an error:

error: unresolved reference: Point
import ua.com.itinnovations.smartbus.data.database.Point
                                                   ^
error: unresolved reference: Point
Point(1, "", 0.0, 0.0, 0, "")
^

My code:
import ua.com.itinnovations.smartbus.data.database.Point
Point(1, β€œβ€, 0.0, 0.0, 0, β€œβ€)

How to import coroutines?

Welcome to Kotlin version 1.6.20-release-285 (JRE 17.0.2+8-Ubuntu-120.04)
Type :help for help, :quit for quit
>>> import kotlinx.coroutines.*
error: unresolved reference: kotlinx
import kotlinx.coroutines.*
       ^