Is this a Kotlin REPL bug?

I can define a value in the Kotlin REPL like this (recursively) without getting an error:

val s: String = s

      

And now I am getting 's' of type NotNull but null.
And I can do something about this value NotNull

with NPE:

>>> val s: String = s

>>> s.length
java.lang.NullPointerException

      

You can try it on your own Kotlin REPL, it works every time.

I am using Kotlin version 1.1.2-3.

+3


source to share


2 answers


Yes, this is a mistake.

val s: String = s
print(s.length)

      

This code compiled successfully, but it gives an error at runtime.



Error: unresolved reference: s


enter image description here

0


source


Yes, this is a REPL bug.

In the REAL Kotlin file it will complain as a "Unresolve reference"



Sorry I cannot post the img, but you can try it in your IDE.

I am using IntelliJ-IDEA 2017.1.3

+2


source







All Articles