Imports in kotlin repl not working?


#1

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

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?


#3

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


#4

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


#5

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, “”)