I'm seeing a strange problem with this: ``` fun gi...
# scripting
c
I'm seeing a strange problem with this:
Copy code
fun gitComplete(line: String, cursorIndex: Int): List<String> {
    val words = line.split(" ")
    if (words[0] == "git") return listOf("commit", "status")
            else return emptyList()
}

val result = if (args.size == 2) gitComplete(args[0], args[1].toInt())
    else emptyList()

result
The script above returns a valid result (a list of strings), but if I remove the intermediate
result
variable:
Copy code
fun gitComplete(line: String, cursorIndex: Int): List<String> {
    val words = line.split(" ")
    if (words[0] == "git") return listOf("commit", "status")
            else return emptyList()
}

if (args.size == 2) gitComplete(args[0], args[1].toInt())
    else emptyList()
then the result of the evaluation by the engine is
null
.
i
This is expected behavior. Script result is the result of the last expression or statement, but the result of statement has type
Unit
. In JSR-223 settings it is conveyed via
null
.
c
Sure but the result of the last expression in the second example is the same as in the first example
i
Ah, sorry, missed this part. Will try to check it.
I reproduced it, will work on a fix.
c
Thanks @ilya.chernikov!